Hi all,
Most of the time for debug purposes I wish to print a list, or a vector
or a set of things which I know that have operator<< defined. It might
be list<intbut it might as well be list<FooBar*where FooBar is a
user-defined class.
So I tried to define a template function which would output a container
with T& or T*. It doesn't work:
template <typename T>
std::ostream& LogDebug(const std::string& n, std::const_iterator<T&>&
b, std::const_iterator<T&>& e) {
for(int i = 0, std::const_iterator it = b; it != e; ++it)
std::cerr << "***" << i++ << ": " << *it << "\n";
return std::cerr;
}
template <typename T>
std::ostream& LogDebug(const std::string& n, std::const_iterator<T*>&
b, std::const_iterator<T*>& e) {
for(int i = 0, std::forward_iterator it = b; it != e; ++it)
std::cerr << "***" << i++ << ": " << **it << "\n";
return std::cerr;
}
I think there's a solution. I just can't find it. Any ideas on how to
work this out?
Regards,
Paulo Matos