Boost logo

Boost :

From: Chris Uzdavinis (chris_at_[hidden])
Date: 2004-10-29 14:53:56


"Neal D. Becker" <ndbecker2_at_[hidden]> writes:

> I'm always writing (e.g.)
>
> std::vector<double> out (size);
> 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),
> u);
> return out;
> }
>
> Then you can say:
>
> std::vector<double> out = transform_r<std::vector<double> > (in, func);

Well, this limits your transformation to only work on the entire range
of the input. I'm also concerned about the overhead of the temporary.

> Since constructors can be elided, I think this may be just as efficient as
> the original, or maybe better.

"Can be" and "may be" doesn't mean "will be."

> OK, perhaps it looks like I didn't save much typing, but when you chain
> function calls you save a lot.

Is the slight savings in typing worth the added restrictions and
potential cost? I'm not inclined to think so.

Too many simple wrappers that barely improve things leads to a
proliferation of similar interfaces that become hard to learn due to
the numerous and subtle differences between them. I like to see
enough improvement to justify the learning curve, etc.

-- 
Chris

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk