0

When using range adaptors in a find algorithm, I have to repeat all the adaptor chain to get the corresponding end() iterator. e.g:

std::vector<size_t> numbers = { 10, 11, 12, 13, 14, 2, 1, 3,3,50, 55} ;

if ( find(numbers|reversed,99) != (numbers|reversed).end() )
                                 //^adaptor chain repeated
{
    std::cout << "FOUND!!!!!" << std::endl;
}

Is there a way to get the corresponding end iterator without having to repeat it again?

Llopeth
  • 406
  • 5
  • 11

1 Answers1

1

Too bad that find calls often end up verbose – it's even worse with STL than with Boost ranges. You could introduce a little helper function:

template<class SinglePassRange, class Value>
bool contains(SinglePassRange& rng, Value const &val) {
  return boost::find(rng, val) != rng.end();
}

I didn't test this so it probably doesn't compile, but you get the idea.

Thomas
  • 174,939
  • 50
  • 355
  • 478