Please take note of the updates at the end of this post.
Update: I have created a public project on GitHub for this library!
I would like to have a single template that once and for all takes care of pretty-printing all STL containers via operator<<. In pseudo code, I'm looking for something like this:
template<container C, class T, String delim = ", ", String open = "[", String close = "]">
std::ostream & operator<<(std::ostream & o, const C<T> …为什么我会收到编译错误no matching function for call to `f( __gnu_cxx::__normal_iterator > >)'?
#include <vector>
template<typename T>
void f(const typename std::vector<T>::iterator &) {}
void g() {
  std::vector<int> v;
  f<int>(v.end());  // Compiles.
  f(v.end());  // Doesn't compile, gcc 4.3 can't find any match.
}
最终,我想编写一个仅需要向量迭代器的函数,并且无法编译其他任何内容(带有有意义的错误)。所以这template<typename T>void f(const T&) {}不是一个好的解决方案,因为它也可以针对其他类型进行编译。