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) |
执行对所包含对象的类型安全访问。
让U
成std::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
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com