Is it possible to create template to the initialization like:
template <typename C> typename C::value_type fooFunction(C& c) {...};
std::vector<string> vec_instance;
fooFunction(cont<0>(vec_instance));
fooFunction(cont<1>(vec_instance));
In general i’m interested is it possible to specify template using integer (ie. 0) instead of true type name.
And how to achieve above?
I’m not completely clear on what you’re asking, but the following snippet works for me:
Two changes worth noting:
An integer is not a type, so if cont is declared
template <typename T>, what you have written will not work.template <int N>is the proper way to parameterize over an integral value, as templatetypedef mentioned.I’m not sure how
cont<>is defined, but from your usage it must be an object you are constructing as a temporary. You will have trouble passing this temporary as a reference intofooFunction. Note that my example above passes C as reference-to-const instead.