Prev: The D Programming Language
Next: CRTP question
From: Terry G on 21 Nov 2006 15:51 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 21 Nov 2006 17:17 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 21 Nov 2006 22:09 > 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 22 Nov 2006 06:09 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 22 Nov 2006 06:42
"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! ] |