template< std::size_t N >
constexpr /* unspecified */ elements = /* unspecified */;
Call signature
(since C++20)Helper concepts
(3) (until C++23)Accepts a
view
of tuple-like values, and issues a view with a value type of the
N
th
element of the adapted view's value-type.
3)Ensures that the elements of the underlying view are tuple-like values
, see tuple-like(since C++23).
4) Ensures that dangling references cannot be returned.
elements_view
models the concepts random_access_range
, bidirectional_range
, forward_range
, input_range
, common_range
, and sized_range
when the underlying view V
models respective concepts.
V
base_
the underlying view
elements_view
sized_range
approximately_sized_range
sized_range
or forward_range
std::ranges::view_interface<D>
) [edit] returns a constant iterator to the beginning of the range
std::ranges::view_interface<D>
) [edit] returns a sentinel for the constant iterator of the range
std::ranges::view_interface<D>
) [edit] returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
std::ranges::view_interface<D>
) [edit] returns the first element in the derived view, provided if it satisfies forward_range
std::ranges::view_interface<D>
) [edit] returns the last element in the derived view, provided only if it satisfies bidirectional_range
and common_range
std::ranges::view_interface<D>
) [edit] returns the n
th element in the derived view, provided only if it satisfies random_access_range
std::ranges::view_interface<D>
) [edit] [edit] Nested classes the iterator type
This specialization of ranges::enable_borrowed_range makes elements_view
satisfy borrowed_range
when the underlying view satisfies it.
#include <iostream> #include <ranges> #include <string> #include <tuple> #include <vector> int main() { const std::vector<std::tuple<int, char, std::string>> vt { {1, 'A', "α"}, {2, 'B', "β"}, {3, 'C', "γ"}, {4, 'D', "δ"}, {5, 'E', "ε"}, }; for (int const e : std::views::elements<0>(vt)) std::cout << e << ' '; std::cout << '\n'; for (char const e : vt | std::views::elements<1>) std::cout << e << ' '; std::cout << '\n'; for (std::string const& e : std::views::elements<2>(vt)) std::cout << e << ' '; std::cout << '\n'; }
Output:
1 2 3 4 5 A B C D E α β γ δ ε[edit] Defect reports
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++20elements_view
was never a borrowed_range
it is a borrowed_range
elements_view
such usage is forbidden [edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4