首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::remove_extent

Defined in header <type_traits>

template< class T > struct remove_extent;

(since C++11)

如果T是某种类型的数组。X,提供成员类型为type等于X,否则typeT注意,如果T是多维数组,则只删除第一个维度。

成员类型

Name

Definition

type

the type of the element of T

帮助者类型

template< class T > using remove_extent_t = typename remove_extent<T>::type;

(since C++14)

可能的实施

模板<class T>结构拆卸[医]范围{tydufT类型;};模板<class T>结构拆卸[医]程度<T。[]>{tydufT类型;};模板<class T,std::size[医]TN>结构删除[医]程度<Tn>{tydufT型;};

*。

二次

代码语言:javascript
复制
#include <iostream>
#include <iterator>
#include <algorithm>
#include <type_traits>
 
template<class A>
typename std::enable_if< std::rank<A>::value == 1 >::type
print_1d(const A& a)
{
    copy(a, a+std::extent<A>::value,
         std::ostream_iterator<typename std::remove_extent<A>::type>(std::cout, " "));
    std::cout << '\n';
}
 
int main()
{
    int a[][3] = {{1,2,3},{4,5,6}};
//  print_1d(a); // compile-time error
    print_1d(a[1]);
}

二次

产出:

二次

代码语言:javascript
复制
4 5 6

二次

另见

is_array (C++11)

checks if a type is an array type (class template)

rank (C++11)

obtains the number of dimensions of an array type (class template)

extent (C++11)

obtains the size of an array type along a specified dimension (class template)

remove_all_extents (C++11)

removes all extents from the given array type (class template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券