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

std::any::any

constexpr any();

(1)

(since C++17)

any( const any& other );

(2)

(since C++17)

any( any&& other );

(3)

(since C++17)

template< class ValueType > any( ValueType&& value );

(4)

(since C++17)

template< class ValueType, class... Args > explicit any( std::in_place_type_t<ValueType>, Args&&... args );

(5)

(since C++17)

template< class T, class U, class... Args > explicit any( std::in_place_type_t<ValueType>, std::initializer_list<U> il, Args&&... args );

(6)

(since C++17)

构造一个新的any对象。

1%29构造一个空对象。

2-3%29拷贝%282%29或移动%283%29内容other在类型和值上与other在构造函数调用之前,或空如果other是空的。正式的,

2%29other是空的,构造的对象是空的。否则,相当于any(std::in_place<T>,std::any_cast<const T&>(other)),在哪里T中包含的对象的类型。other...

3%29other是空的,构造的对象是空的。否则,构造的对象包含other中包含的对象构造为同一类型的对象。other,将该对象视为rvalue。

4%29构造一个具有初始内容的对象(类型对象)。std::decay_t<ValueType>,,,直接初始化从std::forward<ValueType>(value).如果std::is_copy_constructible<std::decay_t<ValueType>>::valuefalse,这个节目的形式不太好。此重载只参与在下列情况下的重载解决方案:std::decay_t<ValueType>any也不是专门的std::in_place_type_t,和std::is_copy_constructible_v<std::decay_t<ValueType>>true...

5%29构造一个具有初始内容的对象(类型对象)。std::decay_t<ValueType>,,,直接-非列表-初始化从std::forward<Args>(args)...。此重载只参与以下情况下的过载解决方案:std::is_constructible_v<std::decay_t<ValueType>, Args...>std::is_copy_constructible_v<std::decay_t<ValueType>>都是true...

6%29构造一个具有初始内容的对象(类型对象)。std::decay_t<ValueType>,,,直接-非列表-初始化从il,std::forward<Args>(args)...。此重载只参与以下情况下的过载解决方案:std::is_constructible_v<std::decay_t<ValueType>,std::initializer_list<U>&, Args...>std::is_copy_constructible_v<std::decay_t<ValueType>>都是true...

模板参数

ValueType

-

contained value type

类型要求

-性病::腐烂[医]T型<ValueType>必须符合CopyConstrucable的要求。

参数

other

-

another any object to copy or move from

value

-

value to initialize the contained value with

il, args

-

arguments to be passed to the constructor of the contained object

例外

1,3%29

noexcept规格:

noexcept

2,4,5,6%29抛出包含类型的构造函数引发的任何异常。

注记

因为默认构造函数是constexpr,静态std::anys被初始化为静态非局部初始化,在任何动态的非本地初始化开始之前。这使得使用类型的对象是安全的。std::any在任何静态对象的构造函数中。

另见

operator=

assigns an any object (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券