Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a container sure to be a range conceptually?

From the documentation of ranges-v3:

view::all

Return a range containing all the elements in the source. Useful for converting containers to ranges.

What makes me confused are:

  1. Under what scenarios are view::all used?
  2. Are standard containers (std::vector, std::list, etc.) not ranges conceptually?

For example:

auto coll = std::vector{ 1, 2, 2, 3 };  
view::all(coll) | view::unique; // version 1
coll | view::unique; // version 2

Is there any difference between version 1 and version 2?

like image 300
szxwpmj Avatar asked Apr 06 '18 01:04

szxwpmj


1 Answers

Egad, that part of the documentation hasn't been updated since range-v3 switched terminology. Yes, a container is a Range (it has begin() and end() that return an iterator/sentinel pair). It is not a View (a Range with O(1) copy/move). So, the documentation for view::all should read:

view::all

Return a View containing all the elements in the source. Useful for converting containers to Views.

To answer your second question, no there is no difference between version 1 and version 2 in your code.

like image 114
Eric Niebler Avatar answered Oct 03 '22 19:10

Eric Niebler