Topic: wouldn't it be nice to have the value_type for each OutputIterator
Author: hamish@firestream.co.uk (Hamish Mackenzie)
Date: Sat, 10 Aug 2002 11:36:53 GMT Raw View
"Steven E. Harris" <seharris@raytheon.com> wrote in message news:<871y99cd0k.fsf@harris.sdo.us.ray.com>...
> ,----
> | template <typename StringType,
> | typename RecordType,
> | typename OutputIterator>
> | OutputIterator copy_all_results(record_set<RecordType>& rs,
> | const StringType& sql,
> | OutputIterator out)
> | // ...
> `----
>
> It may be less convenient to call this version, for the record_set
> argument is not const and hence you can't pass a temporary.
That version of the function is required when you wish the type to be
converted during the copy.
But nine times out of ten I will want to use this function simple to
store the results of a query so that I can modify the table(s) without
fear of invalidating the iterators of the record set. In this case it
would require the caller to provide the same type twice...
std::vector< record_type > results;
odbc::record_set< record_type > rs( con );
copy_all_results( rs, "select * from t", back_inserter( results ) );
..which seems like unnecessary duplication and a potential source of
error.
Not providing value_type for output iterators looks to me like a
potential reduction of type saftey. The only justification for it I
have seen is that more than one type may be assigned to (*out).
Surely you could equaly well write an input iterator that returns a
proxy class with cast operators for several unrelated types? Why have
value_type for input iterators and not output iterators?
Instead I think the standard should require value_type for all
iterators but allow it to be "void" for iterators which work with
multiple types.
Hamish
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Matthias Kronenberger" <mkronen@rhrk.uni-kl.de>
Date: Thu, 1 Aug 2002 12:54:41 CST Raw View
Where do OutputIterators really need a set of value_type s instead of one.
Is that used somewhere. If not, wouldn't it be nice to supply
OutputIterators with value_type?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]