For a rules engine developed in C++, one of the core features is the value type. What I have so far is a bit like a COM-style VARIANT – each value knows its type. There are some rules for type conversion but it’s a bit messy.
I wondered if there are nice drop-in value classes I could use which solve this, without requiring me to use a whole pre-built system. For instance maybe boost has something?
Looking for boost::any or boost::variant?
There are basically three types of variant implementations:
boost::lexical_castis your friend here, orboost::variant…int, stays anintand doesn’t allow to be treated implicitly like anything else — this is theboost::anytypevoid*