Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

back_inserter_iterator

0 views
Skip to first unread message

Hendrik Schober

unread,
Feb 13, 2004, 3:37:34 PM2/13/04
to
Hi,

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


Pete Becker

unread,
Feb 13, 2004, 3:53:47 PM2/13/04
to
Hendrik Schober wrote:
>
> prints "void" both with VC7.1 and Comeau.
> I would have expected it to print "char".
> What am I missing?
>

value_type is only meaningful for readable iterators. For output
iterators it's void.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

Hendrik Schober

unread,
Feb 13, 2004, 4:11:22 PM2/13/04
to
Pete Becker <peteb...@acm.org> wrote:
> Hendrik Schober wrote:
> >
> > prints "void" both with VC7.1 and Comeau.
> > I would have expected it to print "char".
> > What am I missing?
> >
>
> value_type is only meaningful for readable iterators. For output
> iterators it's void.


Dooh! Thanks, Pete.

Is there no way to find the type of
the values an output iterator refers
to?

Pete Becker

unread,
Feb 13, 2004, 5:06:32 PM2/13/04
to
Hendrik Schober wrote:
>
> Pete Becker <peteb...@acm.org> wrote:
> > Hendrik Schober wrote:
> > >
> > > prints "void" both with VC7.1 and Comeau.
> > > I would have expected it to print "char".
> > > What am I missing?
> > >
> >
> > value_type is only meaningful for readable iterators. For output
> > iterators it's void.
>
> 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.

Hendrik Schober

unread,
Feb 16, 2004, 4:09:46 AM2/16/04
to
Pete Becker <peteb...@acm.org> wrote:
> [...]

> > 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!

0 new messages