FreeBSD Manual Pages
std::ranges::range(3) C++ Standard Libary std::ranges::range(3) NAME std::ranges::range - std::ranges::range Synopsis Defined in header <ranges> template< class T > concept range = requires( T& t ) { ranges::begin(t); // equality-preserving for forward iterators (since C++20) ranges::end (t); }; The range concept defines the requirements of a type that allows it- eration over its elements by providing an iterator and sentinel that denote the ele- ments of the range. Semantic requirements Given an expression E such that decltype((E)) is T, T models range only if * [ranges::begin(E), ranges::end(E)) denotes a range, and * both ranges::begin(E) and ranges::end(E) are amortized constant time and do not alter the value of E in a manner observable to equality-preserv- ing expressions, and * if the type of ranges::begin(E) models forward_iterator, ranges::begin(E) is equality-preserving (in other words, forward iterators support multi-pass algorithms) Note: In the definition above, the required expressions ranges::be- gin(t) and ranges::end(t) do not require implicit expression variations. Example // Run this code #include <ranges> #include <vector> #include <iostream> template <typename T> struct range_t : private T { using T::begin, T::end; /*...*/ }; static_assert(std::ranges::range< range_t<std::vector<int>> >); template <typename T> struct scalar_t { T t{}; /* no begin/end */ }; static_assert(not std::ranges::range< scalar_t<int> >); int main() { if constexpr (range_t<std::vector<int>> r; std::ranges::range<de- cltype(r)>) { std::cout << "r is a range\n"; } if constexpr (scalar_t<int> s; not std::ranges::range<de- cltype(s)>) { std::cout << "s is not a range\n"; } } Output: r is a range s is not a range http://cppreference.com 2022.07.31 std::ranges::range(3)
NAME | Synopsis | Example | Output:
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::ranges::range&sektion=3&manpath=FreeBSD+Ports+15.0>
