Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ boost::任何具有有限类型支持的_C++_C++11_Types_Dynamic Typing_Boost Any - Fatal编程技术网

C++ boost::任何具有有限类型支持的

C++ boost::任何具有有限类型支持的,c++,c++11,types,dynamic-typing,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 limited_any x;//x类似于boost::any,但保证只包含int、long或字符串 您建议如何实现这一点?(我自己或使用现有的解决方案)您正在寻

我希望有一个类似于
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
limited_any x;//x类似于boost::any,但保证只包含int、long或字符串

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

您正在寻找。

您可以了解
boost::variant
是如何做到的。虽然
boost::any
是与C的
void*
相当的类型安全,但是
boost::variant
更像C的
union
@tohava注意到有一些区别。最大的实现差异是
any
基于免费存储,而
variant
基于自动存储。(另外,
variant
比任何
都有更丰富的类型安全接口)