1

I'm using the excellent range-v3 library. One of my functions returns a ranges::view object which I'd like to compare to a std::vector. Of course, I can compare element-by-element, but there's got to be a better way.

How to determine equivalence between ranges::view object and std::vector?

jlconlin
  • 14,206
  • 22
  • 72
  • 105

1 Answers1

2

If you want to know if two ranges refer to sequences of equal elements, pass them to the ranges::equal algorithm (DEMO):

int main() {
  std::vector<int> vec{5,4,3,2,1,0};
  assert(ranges::equal(vec, ranges::view::iota(0, 6) | ranges::view::reverse));
}
Casey
  • 41,449
  • 7
  • 95
  • 125
  • I like the ranges library, but often with thorough and complete libraries, it is difficult to know where to find the answer. Thanks for the help! – jlconlin Dec 23 '17 at 00:53