boost::any 类型支持有限

boost::any with limited type support

我希望有一个与 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.