Boost logo

Boost :

From: Victor A. Wagner Jr. (vawjr_at_[hidden])
Date: 2004-10-29 14:53:39

At Friday 2004-10-29 11:34, you wrote:
>I'm always writing (e.g.)
>std::vector<double> out (size);

std::vector<double> out(in.size()); // isn't this what you mean?

>std::transform (in.begin(), in.end(), out.begin(), func);
>Wouldn't it be nice to have versions of the std algorithms that worked like:
>template<typename out_cont_t, typename in_cont_t, typename UnaryOperation>
>inline out_cont_t transform_r (const in_cont_t& in, UnaryOperation u) {
> out_cont_t out (boost::size (in));
> std::transform (boost::begin (in), boost::end (in), boost::begin (out),
> return out;
>Then you can say:
>std::vector<double> out = transform_r<std::vector<double> > (in, func);

it has been a source of astonishment to me since I first learned the STL
that the concept of "range" was never formalized into an
object. containers then could have "free" conversions to range (.begin(),
.end()) .. and the algorithms would take either a range or two iterators
defining it.

>That is, the first template parameter is the desired return container type,
>and the algorithm constructs the return value into it.
>Since constructors can be elided, I think this may be just as efficient as
>the original, or maybe better.
>OK, perhaps it looks like I didn't save much typing, but when you chain
>function calls you save a lot.
>Unsubscribe & other changes:

Victor A. Wagner Jr.
The five most dangerous words in the English language:
               "There oughta be a law"

Boost list run by bdawes at, gregod at, cpdaniel at, john at