🛰️航天仿真算法库 SpaceAST 0.3.1
载入中...
搜索中...
未找到
ast::Any类 参考

#include <Any.hpp>

Public 成员函数

 Any () noexcept=default
 
 Any (const Any &other)
 
 Any (Any &&other) noexcept
 
template<typename ValueType , typename D = typename std::decay<ValueType>::type, typename std::enable_if<!std::is_same< D, Any >::value &&std::is_copy_constructible< D >::value, int >::type = 0>
 Any (ValueType &&value)
 
Any & operator= (const Any &other)
 
Any & operator= (Any &&other) noexcept
 
template<typename ValueType , typename D = typename std::decay<ValueType>::type, typename std::enable_if<!std::is_same< D, Any >::value &&std::is_copy_constructible< D >::value, int >::type = 0>
Any & operator= (ValueType &&value)
 
bool has_value () const noexcept
 
const std::type_info & type () const noexcept
 
void reset () noexcept
 
template<typename T , typename... Args>
std::enable_if<!std::is_reference< T >::value, T & >::type emplace (Args &&... args)
 
void swap (Any &other) noexcept
 

友元

template<typename T >
const T * any_cast (const Any *operand)
 
template<typename T >
T * any_cast (Any *operand)
 
template<typename T >
T any_cast (const Any &operand)
 
template<typename T >
T any_cast (Any &operand)
 
template<typename T >
T any_cast (Any &&operand)
 

详细描述

类型擦除的值容器,与 C++17 的 std::any 接口兼容

在任意时刻持有至多一个任意类型的值,或为空。类型在运行时被类型擦除, 通过 any_cast<T>(any) 在已知目标类型时安全地取回。

使用方式:

Any a = 42; // 持有 int
int v = any_cast<int>(a); // 42
a.emplace<std::string>("hello");
std::string s = any_cast<std::string>(a);
Any empty;
empty.has_value(); // false
empty.type() == typeid(void); // true
类型擦除的值容器,与 C++17 的 std::any 接口兼容
定义 Any.hpp:71
std::enable_if<!std::is_reference< T >::value, T & >::type emplace(Args &&... args)
以给定参数就地构造 T 并替换当前值;返回新值的引用
定义 Any.hpp:173
friend const T * any_cast(const Any *) noexcept
探测式取回(const):类型匹配时返回指针,否则 nullptr
定义 Any.hpp:265
Unit s
秒
定义 Unit.cpp:465

依赖说明:仅支持具基础对齐(alignof(T) <= alignof(max_align_t))且可拷贝构造的类型; 与 std::any 一致,不存储引用类型。拷贝赋值以 copy-and-swap 提供强异常安全保证。


该类的文档由以下文件生成: