Boost logo

Boost :

Subject: Re: [boost] Boost.RangeEx: contains?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-02-22 16:39:26


Eric Niebler wrote:
> Mathias Gaunard wrote:
>> Marcus Lindblom wrote:
>>
>>> I'm just missing basic "contains/contains_if" function, that searches
>>> and retursn a bool on whether an item is in a range. (i.e. find(rng,
>>> v) != end(rng) ). I've found those are quite useful. Perhaps this
>>> just has another name and I overlooked it?
>>
>> What about !empty(rng | filtered(_1 == v)).
>
> Sure, and most algorithms can be implemented in terms of fold. It
> doesn't follow that fold should be the only algorithm.

I assumed the problem with find is that you had to specify rng twice,
which is fairly problematic if rng is a temporary with many adaptors in it.
That is why I offered this solution, which should be just as efficient
as a "contains" function unless I'm missing something, and where rng
only appears once.

I personally prefer have basic building blocks you can combine to do
everything rather than having many functions. That's what languages are
for, and RangeEx is kind of a DSEL.

Using fold for everything wouldn't be very straightforward, however, nor
would it be efficient (it's always a full iteration). It's hardly a
building block, more like a general do-everything algorithm.


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