Paulo Matos wrote:
Quote:
>
In this case, it would if it is list<int>, what about if it is a
list<int*>? How can it be one?
Is there a way to generalize LogDebug or I would have to define
LogDebugPtr and have **it instead of *it in the output line?
#include<iostream>
#include<vector>
#include<iterator>
#include<string>
template <typename T>
std::ostream& LogDebug(const std::string& n,
typename T::const_iterator it,
typename T::const_iterator e)
{
for(int i = 0; it != e; ++it)
std::cerr << "***" << i++ << ": " << *it << "\n";
return std::cerr;
}
template <template<classclass T, typename U>
std::ostream& LogDebug(const std::string& n,
typename T<U*>::const_iterator it,
typename T<U*>::const_iterator e)
{
for(int i = 0; it != e; ++it)
std::cerr << "***" << i++ << ": " << **it << "\n";
return std::cerr;
}
int main(int argc, char* argv[])
{
int a=42, b=1, c=14;
std::vector<intfoo;
foo.push_back(a); foo.push_back(b); foo.push_back(c);
LogDebug<std::vector<int("",foo.begin(),foo.end()) ;
std::vector<int*bar;
bar.push_back(&a); bar.push_back(&b); bar.push_back(&c);
LogDebug<std::vector, int>("",bar.begin(),bar.end());
return 0;
}