this:
#include <iostream>
#include <iterator>
#include <vector>
#include <typeinfo>
template< typename T >
void print_type() {std::cout << typeid(T).name() << '\n';}
template< typename Iter >
void test_iter(Iter it)
{
typedef typename std::iterator_traits<Iter>::value_type value_type;
print_type<value_type>();
}
int main()
{
std::vector<char> v;
test_iter( std::back_inserter(v) );
return 0;
}
prints "void" both with VC7.1 and Comeau.
I would have expected it to print "char".
What am I missing?
Schobi
--
Spam...@gmx.de is never read
I'm Schobi at suespammers dot org
"Sometimes compilers are so much more reasonable than people."
Scott Meyers
value_type is only meaningful for readable iterators. For output
iterators it's void.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Dooh! Thanks, Pete.
Is there no way to find the type of
the values an output iterator refers
to?
Nope. An output iterator has to allow
*iter = x;
for some non-empty set of types on the right-hand side. There's usually
not a single type that you can talk about here.
Yes, that makes sense.
(It's just that I didn't think
about it when I designed this
functions template...)
Thanks!