Search code examples
c++c++11typesdynamic-typingboost-any

boost::any with limited type support


I wish to have a type that acts similarily to boost::any but with a more limited type set. Something like this:

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

How would you recommend implementing this? (Either on my own or using existing solutions)


Solution

  • You are looking for boost::variant.