"Thorsten Ottosen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Alisdair Meredith" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Thorsten Ottosen wrote: > > > > > 2. many standard algorithms take a single output iterator as an > argument. > > > Currently the argument for output must be a container. Should > > > it be posible to specify an iterator here too? > > > > Absolutely! Not all iterators belong to containers eg ostream_iterator > > I see your point. Does anyone have a nice idea of how to detect when the > template argument is an iterator? It's easy with pairs and arrays and the > default case is containers.
The "easy" workaround is maybe to change the template argument to expect an output iterator and not a container: template< typename Container1, typename Container2 > inline typename container_traits<Container2>::iterator copy( const Container1& c1, Container2& c2 ) { return std::copy( begin( c1 ), end( c1 ), begin( c2 ) ); } becomes template< typename Container1, typename Output_iterator > inline typename container_traits<Container2>::iterator copy( const Container1& c1, Output_iterator c2 ) { return std::copy( begin( c1 ), end( c1 ), c2 ); } and usage change accordingly from copy( vector1, vector2 ); to copy( vector1, vector2.begin() ); I see a potential benefit of the former because we can assert that the size of the container is big enough to hold the input. I guess debug iterators would catch the same, if you have them. Still, we need to detect iterators anyway if this should work: istream_iterator< string > is( in_file ), eof; typedef vector< string > vec_t; vec_t text; copy( is, back_inserter( text ) ); // same as std::copy( is, eof, back_inserter( text ) ); We could keep the former syntax and allow inserters like this: template< typename C > std::back_insert_iterator<C>& make_back_inserter( C& c ) { static std::back_insert_iterator<C> bii( c ); bii = back_inserter( c ); return bii; } ... copy( is, make_back_inserter( text ) ); Let me now what you think. regards Thorsten _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost