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
{};
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::type types_vector;
typedef my_union 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::my_union(const my_union &)' : cannot convert parameter 1 from
't1' to 'const my_union &'
with
[
Seq_=types_vector
]
Reason: cannot convert from 't1' to 'const my_union'
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