CW Holeman II
CW Holeman II

Reputation: 4961

C++ Ranges TS include experimental path

I am looking to use C++ Ranges. Working Draft, C++ Extensions for Ranges says:

The Ranges library provides the Ranges library headers, shown in Table 2.

Table 2 — Ranges TS library headers

<experimental/ranges/algorithm>   <experimental/ranges/random>
<experimental/ranges/concepts>    <experimental/ranges/tuple>
<experimental/ranges/functional>  <experimental/ranges/utility>
<experimental/ranges/iterator>

The closest that I found is Range-v3 - Range algorithms, views, and actions for the Standard Library which says:

Range library for C++11/14/17. This code is the basis of a formal proposal to add range support to the C++ standard library.

This library is header-only. You can get the source code from the range-v3 repository on github. To compile with Range-v3, you can either #include the entire library:
#include <range/v3/all.hpp>

Or you can #include only the core, and then the individual headers you want:
#include <range/v3/core.hpp>
#include <range/v3/....

Explain the difference in the includes between Ranges TS with "experimental" & Range V3 without it. Where does one find Ranges with the "experimental/ranges"? What is the significance, does it matter? Is this supposed to be a compiler option that controls this?

Upvotes: 1

Views: 607

Answers (2)

Eric Niebler
Eric Niebler

Reputation: 6177

Range-v3 predates the Ranges TS, and the functionality in the TS is based upon (and is a subset of) the functionality of range-v3. The Ranges TS requires a compiler that supports the Concepts TS; range-v3 does not, so there is no way that range-v3 can be a TS implementation.

If you are looking for a reference implementation of the Ranges TS, find the cmcstl2 project on GitHub.

Upvotes: 3

Nicol Bolas
Nicol Bolas

Reputation: 473447

The Ranges TS is a C++ technical specification. By default, any headers for any library features from a TS are prefixed with "experimental", and anything those headers include go into the namespace std::experimental.

Range-v3 is a C++ library that implements various functionality with regard to ranges. But what it doesn't do is implement the Ranges TS itself. That is, it isn't a formal implementation of the TS. As such, it can put its headers wherever it pleases; it isn't bound by the rules of the TS.

If a compiler implements the Ranges TS, then you can look around in the documentation for what compiler switches are necessary to have access to it (if any). Since the Ranges TS is written against the Concepts TS, you'll probably at least need to activate that. If you download a standalone Ranges TS implementation, then the documentation will (hopefully) tell you what to do in order to use it.

Upvotes: 4

Related Questions