D
Daniel T.
The line marked (1) below compiles fine and does exactly what I would
expect, but the line marked (2) does not compile at all on my system.
error: variable or field 'bar' declared void
My question is, does the standard dictate that the value_type of a
back_inserter is 'void'? If so, why? I would expect the value_type of a
back_inserter to be the same as the value_type of the container it wraps.
template < typename It >
void foo( It it ) {
typename iterator_traits<It>::value_type bar;
cin >> bar;
*it++ = bar;
}
int main() {
vector<int> vec( 1 );
foo( vec.begin() ); // (1)
cout << vec.front();
vector<double> vec2;
foo( back_inserter( vec2 ) ); // (2)
cout << vec2.front();
}
expect, but the line marked (2) does not compile at all on my system.
error: variable or field 'bar' declared void
My question is, does the standard dictate that the value_type of a
back_inserter is 'void'? If so, why? I would expect the value_type of a
back_inserter to be the same as the value_type of the container it wraps.
template < typename It >
void foo( It it ) {
typename iterator_traits<It>::value_type bar;
cin >> bar;
*it++ = bar;
}
int main() {
vector<int> vec( 1 );
foo( vec.begin() ); // (1)
cout << vec.front();
vector<double> vec2;
foo( back_inserter( vec2 ) ); // (2)
cout << vec2.front();
}