N
nguillot
Hello.
I would like to specialize a templated function for the type
std::vector<U>, U being a typename.
I think it is not possible.
However I read on forum we can (I describe just after how) but I guess
this is not specialization but overload.
I’ve got 2 questions:
1) Is it specialization or overload?
2) In fact, if it works, I don’t really care the answer of this
question 1 (execpt for my knowledge): does the standard assure it
works (resolution order) ?
Now the stuff:
Let’s have the template function:
template <typename T>
void f(const T& p_value)
{
cout << "generic" << endl;
}
The specialization (for bool for instance) is
template <>
void f<bool>(const bool& p_value)
{
cout << "bool" << endl;
}
The "specialization" for vector<U> is (or is it an overload?)
template <typename U>
void f(const std::vector<U> & p_value)
{
cout << "vector" << endl;
}
And indeed if I do :
int i;
vector<double> v;
bool b;
f(i);
f(v);
f(b);
I get:
generic
vector
bool
So, is it really specialization?
If no, am I sure f(v) will always calls this "specialization?
Thanks in advance.
I would like to specialize a templated function for the type
std::vector<U>, U being a typename.
I think it is not possible.
However I read on forum we can (I describe just after how) but I guess
this is not specialization but overload.
I’ve got 2 questions:
1) Is it specialization or overload?
2) In fact, if it works, I don’t really care the answer of this
question 1 (execpt for my knowledge): does the standard assure it
works (resolution order) ?
Now the stuff:
Let’s have the template function:
template <typename T>
void f(const T& p_value)
{
cout << "generic" << endl;
}
The specialization (for bool for instance) is
template <>
void f<bool>(const bool& p_value)
{
cout << "bool" << endl;
}
The "specialization" for vector<U> is (or is it an overload?)
template <typename U>
void f(const std::vector<U> & p_value)
{
cout << "vector" << endl;
}
And indeed if I do :
int i;
vector<double> v;
bool b;
f(i);
f(v);
f(b);
I get:
generic
vector
bool
So, is it really specialization?
If no, am I sure f(v) will always calls this "specialization?
Thanks in advance.