[range.elements.overview]

# 25 Ranges library [[ranges]](./#ranges)

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.elements.overview)

### 25.7.23 Elements view [[range.elements]](range.elements#overview)

#### 25.7.23.1 Overview [range.elements.overview]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L10131)

elements_view takes
a view of tuple-like values and a size_t, and
produces a view with a value-type of the Nth element
of the adapted view's value-type[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L10137)

The name views​::​elements<N> denotes
a range adaptor object ([[range.adaptor.object]](range.adaptor.object "25.7.2 Range adaptor objects"))[.](#2.sentence-1)

Given a subexpression E and constant expression N,
the expression views​::​elements<N>(E) is expression-equivalent toelements_view<views​::​all_t<decltype((E))>, N>{E}[.](#2.sentence-2)

[*Example [1](#example-1)*: auto historical_figures = map{ pair{"Lovelace"sv, 1815}, {"Turing"sv, 1912}, {"Babbage"sv, 1791}, {"Hamilton"sv, 1936}};

auto names = historical_figures | views::elements<0>;for (auto&& name : names) { cout << name << ' '; // prints Babbage Hamilton Lovelace Turing }auto birth_years = historical_figures | views::elements<1>;for (auto&& born : birth_years) { cout << born << ' '; // prints 1791 1936 1815 1912 } â *end example*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L10166)

keys_view is an alias for elements_view<R, 0>, and
is useful for extracting keys from associative containers[.](#3.sentence-1)

[*Example [2](#example-2)*: auto names = historical_figures | views::keys;for (auto&& name : names) { cout << name << ' '; // prints Babbage Hamilton Lovelace Turing } â *end example*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L10179)

values_view is an alias for elements_view<R, 1>, and
is useful for extracting values from associative containers[.](#4.sentence-1)

[*Example [3](#example-3)*: auto is_even = [](const auto x) { return x % 2 == 0; };
cout << ranges::count_if(historical_figures | views::values, is_even); // prints 2 â *end example*]
