Spec-Zone.ru › C++

std::tuple_element<std::array>

Определено в заголовке <array>
template< std::size_t I, class T, std::size_t N >
struct tuple_element< I, std::array<T, N> >;
(с C++11)

Предоставляет индексированный доступ во время компиляции к типу элементов массива с использованием интерфейса типа кортежа.

Типы членов

Тип члена Определение
type тип элементов массива

Возможная реализация

template<std::size_t I, class T>
struct tuple_element;
 
template<std::size_t I, class T, std::size_t N>
struct tuple_element<I, std::array<T,N>>
{
    using type = T;
};

Пример

#include <array>
#include <tuple>
#include <type_traits>
 
int main()
{
    // define array and get the type of the element at position 0
    std::array<int, 10> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    using T = std::tuple_element<0, decltype(data)>::type; // int
    static_assert(std::is_same_v<T, int>);
 
    const auto const_data = data;
    using CT = std::tuple_element<0, decltype(const_data)>::type; // const int
 
    // the result of tuple_element depends on the cv-qualification of the tuple-like type
    static_assert(!std::is_same_v<T, CT>);
    static_assert(std::is_same_v<CT, const int>);
}

См. также

Структурированное связывание (C++17) связывает указанные имена с подобъектами или элементами кортежа инициализатора
std::tuple_element<std::tuple>
(C++11)
получает тип указанного элемента
(специализация шаблона класса)
std::tuple_element<std::pair>
(C++11)
получает тип элементов pair
(специализация шаблона класса)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/array/tuple_element

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API