From: Terry G on
The following prints "void", which seems to be what the standard intends.
I expected to see something like "int".

// Deleted headers.
using namespace std;
int main() {
typedef vector<int> IntVec;
typedef back_insert_iterator<IntVec> IntVecBackInserter;
IntVec v;
IntVecBackInserter iter = back_inserter(v);
cout << typeid(iterator_traits<IntVecBackInserter>::value_type).name()
<< endl;
} // main

terry



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Alberto Ganesh Barbati on
Terry G ha scritto:
> The following prints "void", which seems to be what the standard intends.
> I expected to see something like "int".
>
> // Deleted headers.
> using namespace std;
> int main() {
> typedef vector<int> IntVec;
> typedef back_insert_iterator<IntVec> IntVecBackInserter;
> IntVec v;
> IntVecBackInserter iter = back_inserter(v);
> cout << typeid(iterator_traits<IntVecBackInserter>::value_type).name()
> << endl;
> } // main
>

Because back_inserter_iterator<> is an output iterator but not an input
iterator. value_type, which is defined as the type able to hold the
value of the expression *it, makes sense only for input iterators.

Ganesh

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Terry G on
> Because back_inserter_iterator<> is an output iterator but not an input
> iterator. value_type, which is defined as the type able to hold the
> value of the expression *it, makes sense only for input iterators.

What if I want to know what type *it will return?

terry



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Carl Barron on
In article <ek092f$mp0$1(a)news.netins.net>, Terry G
<tjgolubi(a)netins.net> wrote:

> > Because back_inserter_iterator<> is an output iterator but not an input
> > iterator. value_type, which is defined as the type able to hold the
> > value of the expression *it, makes sense only for input iterators.
>
> What if I want to know what type *it will return?
>
> terry

back_inserter_Iterator does have a nested typedef container_type which
is the type of the container the that is used with the push_back
operation. This effectively gives the value_type of what was pushed
container_type::value_type. Is that what you want, given only a
back_inserter_iterator<C> where C is not stated in your code??

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: P.J. Plauger on
"Terry G" <tjgolubi(a)netins.net> wrote in message
news:ek092f$mp0$1(a)news.netins.net...

>> Because back_inserter_iterator<> is an output iterator but not an input
>> iterator. value_type, which is defined as the type able to hold the
>> value of the expression *it, makes sense only for input iterators.
>
> What if I want to know what type *it will return?

You can only assign to *it and increment it with ++it or it++.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: The D Programming Language
Next: CRTP question