1

I was checking C++20 Range Library on en.cppreference.com. Roughly speaking, it looks like to be compliant to the Range concept a type needs to have begin and end iterator accessors. This should make every container in STL be compliant to the Range concept. However, when I checked some containers constructors I saw that they still have the overload taking explicitly begin and end iterators as input, but no overload taking simply just one range object.

Is it because en.cppreference.com is not yet updated, or is it standardized that we will not be able to construct a container using just range?

Barry
  • 286,269
  • 29
  • 621
  • 977
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64
  • I don't see anything in C++20 that actually added an overloaded constructor to containers that takes a Range parameter. – Sam Varshavchik May 27 '20 at 13:03
  • 2
    I found https://wg21.link/P1206r0 and its revision https://wg21.link/P1206r1 that propose that constructors taking ranges or a new `ranges::to(range);` function. Since these exist, I assume nothing is in the standards yet – Artyer May 27 '20 at 13:03
  • 1
    Does this answer your question? [Initializing std::vector with ranges library](https://stackoverflow.com/questions/61841418/initializing-stdvector-with-ranges-library) – Davis Herring May 28 '20 at 02:58
  • As I recall, there were kinks to work out and not enough time before C++20. You could try looking through trip reports for a better explanation. – chris May 28 '20 at 16:28
  • @DavisHerring Yes, thanks. Missed opportunity to not have a dedicated ctor already in C++20 though. – nyarlathotep108 May 29 '20 at 16:01
  • 1
    @nyarlathotep108: They tried that and found that it didn’t work well—constructor overload sets are hard. – Davis Herring May 29 '20 at 16:53
  • @DavisHerring I actually tried in trunk gcc, I define two constructor overloads for the same `struct` one that takes an `std::integral` and another one which takes `std::ranges::range`, and they work perfectly fine. This means that in theory they could have disambiguated the container constructor which takes an allocator type to the one which takes a range type. :/ – nyarlathotep108 Jun 08 '20 at 14:36

0 Answers0