- Notifications
You must be signed in to change notification settings - Fork452
Range library for C++14/17/20, basis for C++20's std::ranges
License
ericniebler/range-v3
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Range library for C++14/17/20. This code was the basis ofa formal proposal to add range support to the C++ standard library. That proposal evolved through a Technical Specification, and finally intoP0896R4 "The One Ranges Proposal" which was merged into the C++20 working drafts in November 2018.
Ranges are an extension of the Standard Template Library that makes its iterators and algorithms more powerful by making themcomposable. Unlike other range-like solutions which seek to do away with iterators, in range-v3 ranges are an abstraction layeron top of iterators.
Range-v3 is built on three pillars: Views, Actions, and Algorithms. The algorithms are the same as those with which you are already familiar in the STL, except that in range-v3 all the algorithms have overloads that take ranges in addition to the overloads that take iterators. Views are composable adaptations of ranges where the adaptation happens lazily as the view is iterated. And an action is an eager application of an algorithm to a container that mutates the container in-place and returns it for further processing.
Views and actions use the pipe syntax (e.g.,rng | adapt1 | adapt2 | ...
) so your code is terse and readable from left to right.
Check out the (woefully incomplete) documentationhere.
Other resources (mind the dates, the library probably has changed since then):
Usage:
- Talk:CppCon 2015: Eric Niebler "Ranges for the Standard Library", 2015.
- A slice of Python in C++, 07.12.2014.
- Actions (back then calledContainer Algorithms), 23.11.2014.
- Range comprehensions, 27.04.2014.
- Input iterators vs input ranges, 07.11.2013.
Design / Implementation:
- Rationale behind range-v3:N4128: Ranges for the standard library Revision 1, 2014.
- Ranges TS:N4560: C++ Extensions for Ranges, 2015.
- Implementation of customization points in range-v3:
- Proxy iterators in range-v3:
- Metaprogramming utilities:
- See themeta documentation, the library has changed significantly since the2014 blog post.
- Concept emulation layer:Concept checking in C++11, 2013.
- C++Now 2014: Eric Niebler "C++11 Library Design", 2014.
Most of the source code in this project are mine, and those are under the Boost Software License. Parts are taken from Alex Stepanov's Elements of Programming, Howard Hinnant's libc++, and from the SGI STL. Please see the attached LICENSE file and the CREDITS file for the licensing and acknowledgments.
The code is known to work on the following compilers:
- clang 5.0 (or later)
- GCC 6.5 (or later)
- Clang/LLVM 6 (or later) on Windows (older versions may work - we haven't tested.)
- Visual Studio 2019 (or later) on Windows, with some caveats due to range-v3's strict conformance requirements:
- range-v3 needs
/permissive-
and either/std:c++latest
,/std:c++20
, or/std:c++17
- range-v3 needs
Development Status: This code is fairly stable, well-tested, and suitable for casual use, although currently lacking documentation.In general, no promise is made about support or long-term stability. This codewill evolve without regard to backwards compatibility.
A notable exception is anything found within theranges::cpp20
namespace. Those components will change rarely or (preferably) never at all.
Build status
You can download and install range-v3 using thevcpkg dependency manager:
git clone https://github.com/Microsoft/vcpkg.gitcd vcpkg./bootstrap-vcpkg.sh./vcpkg integrate install./vcpkg install range-v3
The range-v3 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, pleasecreate an issue or pull request on the vcpkg repository.
You can install pre-built binaries for range-v3 or build it from source usingConan.
Setup yourCMakeLists.txt
:
project(myproject CXX)add_executable(${PROJECT_NAME} main.cpp)find_package(range-v3 REQUIRED)target_link_libraries(${PROJECT_NAME} range-v3::range-v3)
Create aconanfile.txt
:
[requires]range-v3/[*][generators]CMakeDepsCMakeToolchain
Run following commands:
$ conan install. --build=missing --output-folder=build$ cmake. -B build -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake$ cmake --build build
For detailed instructions on how to use Conan, please refer to theConan documentation.
The range-v3 package in Conan Center is kept up to date by Conan team members and Conan community contributors.If the version is out of date, pleasecreate an issue or pull request on the conan repository.
You can usebuild2
, a dependency manager and build-system combined, to userange-v3
(or work on it):
Currently this package is available in these package repositories:
- https://cppget.org/range-v3/ for released and published versions.
- The git repository with the sources of the
build2
package ofrange-v3
for unreleased or custom revisions ofrange-v3
, or for working on it withbuild2
.
build2
package name:range-v3
- Library target name :
lib{range-v3}
- Detailed use cases and instructions in this document.
For example, to make yourbuild2
project depend onrange-v3
:
- Add one of the repositories to your configurations, or in your
repositories.manifest
, if not already there; for example::role: prerequisitelocation: https://pkg.cppget.org/1/alpha # v0.11.0 is there.
- Add this package as a dependency to your
manifest
file (example forv0.11.x
):depends: range-v3 ~0.11.0
- Import the target and use it as a prerequisite to your own target using
range-v3
in the appropriatebuildfile
:importrange_v3=range-v3%lib{range-v3}lib{mylib} :cxx{**} ... $range_v3
Then just build your project as usual (withb
orbdep update
),build2
will figure out the rest.
Forbuild2
newcomers or to get more details and use cases, you can readthis document and thebuild2
toolchain introduction.
About
Range library for C++14/17/20, basis for C++20's std::ranges