Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-06-21 09:26:03


Dear Boosters,

I have some strange problem and don't understand if this is really intended so by the C++ standard
or is this a bug in the compiler of MS Visual C++ 2003 & 2005.

I have a template class which receives an mpl::vector with possible storage types. This class
contains an instance of boost::variant but is intended to wrap it with a little bit different
functionality.

//Solution A
//A body of a _working__ solution:
template<class Seq_>
class my_union
{
  public:
    template<class T>
       my_union(const T& rhs) {...}

  //...
};

//Solution B
//not working more general solution
 //this struct compiles fine
template<T>
struct const_ref
  : boost::add_const<typename boost::add_reference<T>::type>
{};

template<class Seq_>
class my_union
{
  public:
    template<class T>
      my_union(typename const_ref<T>::type rhs) {...}
  //...
};

now call of the class:

        //assume my_pair is defined earlier
        //assume classes A,B,C,D are defined upon
        typedef my_pair<0, A> t1;
        typedef my_pair<1, B> t2;
        typedef my_pair<2, C> t3;
        typedef my_pair<3, A> t4;

        typedef mpl::vector<t1,t2,t3,t4>::type types_vector;

        typedef my_union<types_vector> union_t;

        t1 t(A());

        union_t u(t); //error! with Solution B, but fine with Solution A

in the my_union I get an error stating:

error C2664: 'my_union<Seq_>::my_union(const my_union<Seq_> &)' : cannot convert parameter 1 from
't1' to 'const my_union<Seq_> &'
        with
        [
            Seq_=types_vector
        ]
        Reason: cannot convert from 't1' to 'const my_union<Seq_>'
        with
        [
            Seq_=types_vector
        ]
        No user-defined-conversion operator available that can perform this conversion, or the
operator cannot be called

Why does Solution A work fine and Solution B does not? Is this really intended by a standard?

With Kind Regards,

Ovanes Markarian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net