Spec-Zone.ru › C++

std::remove_all_extents

Определён в заголовочном файле <type_traits>
template< class T >
struct remove_all_extents;
(начиная с C++11)

Если T — многомерный массив некоторого типа X, предоставляет псевдоним типа-член type, равный X; в противном случае type — это T.

Если программа добавляет специализации для std::remove_all_extents, поведение не определено.

Типы-члены

Имя Определение
type тип элемента T

Вспомогательные типы

template< class T >
using remove_all_extents_t = typename remove_all_extents<T>::type;
(начиная с C++14)

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

template<class T>
struct remove_all_extents { typedef T type; };

template<class T>
struct remove_all_extents<T[]>
{
    typedef typename remove_all_extents<T>::type type;
};

template<class T, std::size_t N>
struct remove_all_extents<T[N]>
{
    typedef typename remove_all_extents<T>::type type;
};

Пример

#include <iostream>
#include <type_traits>
#include <typeinfo>

template<class A>
void info(const A&)
{
    typedef typename std::remove_all_extents<A>::type Type;
    std::cout << "underlying type: " << typeid(Type).name() << '\n';
}

int main()
{
    float a0;
    float a1[1][2][3];
    float a2[1][1][1][1][2];
    float* a3;
    int a4[3][2];
    double a5[2][3];
    struct X { int m; } x0[3][3];

    info(a0);
    info(a1);
    info(a2);
    info(a3);
    info(a4);
    info(a5);
    info(x0);
}

Возможный вывод:

underlying type: float
underlying type: float
underlying type: float
underlying type: float*
underlying type: int
underlying type: double
underlying type: main::X

См. также

is_array
(C++11)
проверяет, является ли тип типом массива
(шаблон класса)
rank
(C++11)
получает количество измерений типа массива
(шаблон класса)
extent
(C++11)
получает размер типа массива вдоль указанного измерения
(шаблон класса)
remove_extent
(C++11)
удаляет одно измерение из заданного типа массива
(шаблон класса)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/types/remove_all_extents

Spec-Zone.ru

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