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

std::any_cast

template<class ValueType> ValueType any_cast(const any& operand);

(1)

(since C++17)

template<class ValueType> ValueType any_cast(any& operand);

(2)

(since C++17)

template<class ValueType> ValueType any_cast(any&& operand);

(3)

(since C++17)

template<class ValueType> const ValueType* any_cast(const any* operand);

(4)

(since C++17)

template<class ValueType> ValueType* any_cast(any* operand);

(5)

(since C++17)

执行对所包含对象的类型安全访问。

Ustd::remove_cv_t<std::remove_reference_t<ValueType>>...

1%29该项目的格式不正确,如果is_constructible_v<ValueType, const U&>不是true...

2%29该项目的格式不正确,如果is_constructible_v<ValueType, U&>不是true...

3%29该项目的格式不正确,如果is_constructible_v<ValueType, U>不是true...

参数

operand

-

target any object

返回值

1-2%29static_cast<ValueType>(*std::any_cast<U>(&operand))

3%29static_cast<ValueType>(std::move(*std::any_cast<U>(&operand)))...

4-5%29operand不是空指针,而typeid所要求的ValueType的内容与operand,指向操作数包含的值的指针,否则为空指针。

例外

1-3%29投std::bad_any_cast如果typeid所要求的ValueType的内容不匹配。operand...

4-5%29

noexcept规格:

noexcept

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

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

扫码关注腾讯云开发者

领取腾讯云代金券