tags:

views:

70

answers:

1

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?

+7  A: 

Looking for boost::any or boost::variant?

There are basically three types of variant implementations:

  1. A type that can be freely casted between types (think untyped languages) -- boost::lexical_cast is your friend here, or boost::variant...
  2. A type that can hold any type, but is typesafe -- e.g. initialized with an int, stays an int and doesn't allow to be treated implicitly like anything else -- this is the boost::any type
  3. The evil allow anything type -- cast to what you want without error checking, no type information held -- think void*
Kornel Kisielewicz
Sounds more like he wants boost::variant. http://www.boost.org/doc/html/variant.html
Roger Pate
@Roger : Yeah, noticed that right after posting
Kornel Kisielewicz
I need to look more closely but boost::variant sounds like the answer, to save me writing all that stuff from scratch.
John