views:

252

answers:

4

hello

Are there any standard/de facto standard (boost) wrappers around standard algorithms which work with containers defining begin and end. Let me show you what I mean with the code:

// instead of specifying begin and end
std::copy(vector.begin(), vector.end(), output);
// write as
xxx::copy(vector, output);

I know it can be written easily, but I am looking specifically for something ubiquitous. Thanks.

+1  A: 

The only case where I've seen something like this are those algorithms based upon the boost::range library, but even these do not actually modify the standard algorithms like std::copy or std::remove_if -- the algorithm in question needs to be written to take advantage of such a range wrapper.

For an example, see the Boost String Algorithms library.

Billy ONeal
+2  A: 

The next standard will (hopefully!) amend this. In the meantime, take a look at Boost.Range and its various uses although I’m not aware of an interface to the standard algorithms.

Konrad Rudolph
do you mean TR1?
aaa
TR1 does not include a range facility. The Wikipedia page for C++0x lists a few items about range semantics, but they are referring to the range-based for loop which is new in C++0x. AFAIK the standard algorithms are not being modified in the new standard -- though I could be wrong....
Billy ONeal
@unknown: No, TR1 isn’t strictly a new standard, it’s just a bunch of recommendations. I was speaking of C++0x (although that’s indeed missing from the Wikipedia article – but it *was* planned. Not sure if it made it into the final draft).
Konrad Rudolph
It was part of Stroustrup's "concepts" proposal which isn't in C++0x. The library changes would have been great to have, but that had to be balanced against the complexity of concepts as a language feature.
Jason Orendorff
@Jason: hmm, pity. But concepts aren’t actually needed for this, since the range is just a holder for two iterators so I don’t see why this was removed along with concepts.
Konrad Rudolph
+6  A: 

There is an extension to the Boost Range library called RangeEx which contains range wrappers for all stl algorithms, plus some new ones.

It has recently been accepted into Boost and so it's not yet in the current "official" release (1.41). Until this changes, you can download the latest version from the Boost Vault.

Don't know if this will ever become part of the C++ standard, but the fact that it's in Boost means that it will be the de facto standard.

Manuel
thanks, boost vault is good enough for me.
aaa
fyi, RangeEx has been integrated into Boost Range as of 1.43.0
sstock
A: 

I will add my own finding: Adobe source libraries (rangex from boost supersedes algorithms part) ASL

aaa