Hi.
Many algorithms in the string-algo library have 3 versions (I'll take
to_upper as an example):
1. In-place modification which takes a SequenceT by ref:
template<typename MutableCollectionT>
void to_upper(MutableCollectionT &);
2. Copy version which takes a SequenceT by const ref, and returns SequenceT:
template<typename SequenceT>
SequenceT to_upper_copy(const SequenceT &);
3. Copy version which takes a const ref CollectionT and an
OutputIteratorT and the OutputIteratorT after using it:
template
OutputIteratorT to_upper_copy(OutputIteratorT, const CollectionT &)
I believe there's room for another version - something that takes a
const ref CollectionT, and returns a copy in a SequenceT:
template
SequenceT to_upper_copy(const CollectionT &);
The benefits are ease of use combined with performance. IMO, a common
scenario is to perform a copy algorithm on a char* string, and returning
it as a std::string. Such a thing would be easily done with the
proposed extension as:
std::string str = to_upper_copystd::string("something");
As it is now, I either have to make additional copy (if I use the
in-place modification version or the SequenceT copy version), or handle
the std::string size my self (if I use the OutputIteratorT version). The
new version will allow me to do it elegantly and efficiently. The
problem is that it probably can't be an overload of to_upper_copy
because it has the same number of arguments as one of the existing
overloads, so it will have to have a different name :-(
Thanks,
Yuval