C++ universal data type
<p>I have a universal data type, which is passed by value, but does not maintain the type information. We store only pointers and basic data types(like int, float etc) inside this. Now for the first time, we need to store std::string inside this. So we decided to convert it into std::string* and store it. Then comes the problem of destruction. We don't like to copy the std::string every time. So i am thinking of an approach like this. Say the data type looks like this</p>

<pre><code>class Atom
{
public :
     enum flags
     {
         IS_STRING,
         IS_EMPTY,
         HAS_GOT_COPIED,

         MARKER
     };

private:
     void*   m_value;
     std::bitset&lt;MARKER&gt;   m_flags;

public:
    .....
    Atom( Atom&amp; atm )
    {
        atm.m_flags.set( HAS_GOT_COPIED );
        ..... 
    }
    .....
    ~Atom()
    {
        if( m_flags.test(IS_STRING) &amp;&amp; !m_flags.test(HAS_GOT_COPIED) )
        {
             std::string*  val = static_cast&lt;std::string*&gt;(m_value);
             delete val;
        }
    }
};
</code></pre>

<p>Is this a good approach to find out whether there is no more reference to std::string*? Any comments..</p>

<p>I have looked at boost::any and poco::DynamicAny. Since i need serialization, i can't use those.</p>

<p>Thanks,
Gokul.</p>
