OT: Why can't I insert a vector of int

I simplified this as much as possible and it turned into a template question, and not a boost question, but I hope that someone here will take a second and answer it anyway. I don't know of another mailing list with the expertise of this one in templates. In the below, the inserter for vector<int> is never used, instead, since the vector<int> is a type, it matches the simpler inserter for T. How can I make it work the way I want it to? #include <iostream> #include <vector> struct theclass { template<typename T> void operator<<(const T& t){ std::cout << "Got a T\n"; } template<typename T> void operator<<(std::vector<const T> t){ std::cout << "Got a vector of T\n"; } }; int main() { std::vector<int> vi; int i; theclass f; f << i; f << vi; }

void operator<<(std::vector<const T> t){ std::cout << "Got a vector of
Because this overload matches "const T". The vector declared in your main is "vector<int>". Template argument deduction won't match vector<int> because isn't of the form vector<const int>. Andrew

I simplified this as much as possible and it turned into a template question, and not a boost question, but I hope that someone here will take a second and answer it anyway. I don't know of another mailing list with the expertise of this one in templates.
http://groups.google.com/group/comp.lang.c++.moderated/topics
participants (3)
-
Andrew Sutton
-
Igor R
-
Patrick Horgan