Boost logo

Boost :

Subject: Re: [boost] [Algorithm] contains(v, 1)
From: Robert Ramey (ramey_at_[hidden])
Date: 2018-05-31 12:50:42


On 5/31/18 3:14 AM, Olaf van der Spek via Boost wrote:
> Hi,
>
> vector<int> v;
> contains(v, 1);
>
> This doesn't work as contains expects two ranges (AFAIK).
> Is there some other function that's usable for this purpose?
> Should contains support a value for argument 2?
>
> Gr,
>

Hmmm- can't you just make your own? Something like ...

#include <algorithm>

template<typename V>
bool contains(const V & v, const typename V::value_type & t){
        return v.end != find(v.begin(), v.end(), t);
}

I'm pretty sure it would work on strings as well.

Robert Ramey


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