| ||||||||||||||||||||||
| Range primitives | |||||||
| |||||||
| Range concepts | |||||||||||||||||||
| |||||||||||||||||||
| Range factories | |||||||||
| |||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper items | |||||||||||||||||
| |||||||||||||||||
Defined in header <ranges> | ||
template<ranges::input_range V,std::size_t N> requiresranges::view<V>&& | (1) | (since C++20) |
namespace views{ template<std::size_t N> | (2) | (since C++20) |
Call signature | ||
template<ranges::viewable_range R> requires/* see below */ | (since C++20) | |
Helper concepts | ||
| (3) | ||
template<class T,std::size_t N> concept/*has-tuple-element*/= | (until C++23) (exposition only*) | |
template<class T,std::size_t N> concept/*has-tuple-element*/= | (since C++23) (exposition only*) | |
template<class T,std::size_t N> concept returnable-element= | (4) | (exposition only*) |
view of tuple-like values, and issues a view with a value type of theNth element of the adapted view's value-type.views::elements is aRangeAdaptorObject. The expressionviews::elements<M>(e) isexpression-equivalent toelements_view<views::all_t<decltype((e))>, M>{e} for any suitable subexpressione and constant expressionM.elements_view models the conceptsrandom_access_range,bidirectional_range,forward_range,input_range,common_range, andsized_range when the underlying viewV models respective concepts.
Contents |
| Member | Description |
Vbase_ | the underlying view (exposition-only member object*) |
constructs aelements_view(public member function)[edit] | |
| returns a copy of the underlying (adapted) view (public member function)[edit] | |
| returns an iterator to the beginning (public member function)[edit] | |
| returns an iterator or a sentinel to the end (public member function)[edit] | |
returns the number of elements, provided only if the underlying (adapted) range satisfiessized_range(public member function)[edit] | |
(C++26) | returns the approximate size of the resultingapproximately_sized_range(public member function)[edit] |
Inherited fromstd::ranges::view_interface | |
returns whether the derived view is empty, provided only if it satisfiessized_range orforward_range(public member function of std::ranges::view_interface<D>)[edit] | |
(C++23) | returns a constant iterator to the beginning of the range (public member function of std::ranges::view_interface<D>)[edit] |
(C++23) | returns a sentinel for the constant iterator of the range (public member function of std::ranges::view_interface<D>)[edit] |
| returns whether the derived view is not empty, provided only ifranges::empty is applicable to it (public member function of std::ranges::view_interface<D>)[edit] | |
returns the first element in the derived view, provided if it satisfiesforward_range(public member function of std::ranges::view_interface<D>)[edit] | |
returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range(public member function of std::ranges::view_interface<D>)[edit] | |
returns thenth element in the derived view, provided only if it satisfiesrandom_access_range(public member function of std::ranges::view_interface<D>)[edit] | |
| the iterator type (exposition-only member class template*) | |
| the sentinel type (exposition-only member class template*) |
template<class T,std::size_t N> constexprbool enable_borrowed_range<std::ranges::elements_view<T, N>>= | (since C++20) | |
This specialization ofranges::enable_borrowed_range makeselements_view satisfyborrowed_range when the underlying view satisfies it.
#include <iostream>#include <ranges>#include <string>#include <tuple>#include <vector> int main(){conststd::vector<std::tuple<int,char,std::string>> vt{{1,'A',"α"},{2,'B',"β"},{3,'C',"γ"},{4,'D',"δ"},{5,'E',"ε"},}; for(intconst e: std::views::elements<0>(vt))std::cout<< e<<' ';std::cout<<'\n'; for(charconst e: vt| std::views::elements<1>)std::cout<< e<<' ';std::cout<<'\n'; for(std::stringconst& e: std::views::elements<2>(vt))std::cout<< e<<' ';std::cout<<'\n';}
Output:
1 2 3 4 5A B C D Eα β γ δ ε
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3494 | C++20 | elements_view was never aborrowed_range | it is aborrowed_rangeif its underlying view is |
| LWG 3502 | C++20 | dangling reference could be obtained fromelements_view | such usage is forbidden |
(C++20) | takes aview consisting of pair-like values and produces aview of the first elements of each pair(class template)(range adaptor object)[edit] |
takes aview consisting of pair-like values and produces aview of the second elements of each pair(class template)(range adaptor object)[edit] | |
(C++23) | aview consisting of tuples of references to corresponding elements of the adapted views(class template)(customization point object)[edit] |
aview consisting of results of application of a transformation function to corresponding elements of the adapted views(class template)(customization point object)[edit] | |
| BLAS-like slice of a valarray: starting index, length, stride (class)[edit] |