c++ - boost::any 类型支持有限

标签 c++ c++11 types dynamic-typing boost-any

我希望有一个与 boost::any 行为相似但类型集更有限的类型。像这样:

limited_any<int,long,string> x; // x is like boost::any but is guaranteed to contain only an int, a long, or a string

您建议如何实现? (我自己或使用现有解决方案)

最佳答案

您正在寻找boost::variant .

关于c++ - boost::any 类型支持有限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28413265/

相关文章:

c++ - 推断 CRTP 中模板化成员函数的返回类型

c++ - std::stable_sort 根本不稳定?

scala - 单例类型中的表面不一致

c++ - 涉及嵌套模板参数和默认值的模板类型推导

c++ - 蒙提霍尔程序 C++

c++ - 实现 pimpl 习惯用法时出现链接器错误

c++11 - 为什么仅声明的友元函数不能有默认参数?

struct - 指向结构 slice 的预期指针

python - Cython:访问 CPython 对象的私有(private) C 成员

c++ - 基数桶搜索