Re: [eigen] Can we prevent that this compiles?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I think I prefer the second solution. It's less hassle... there were even a third solution when it were possible to take the Matrix ctors explicit.. But there I think we rely on the implicit conversion.

Anyways, your ideas are cool and it's good that we can easily make the code more safe!

Cheers,
Hauke

On Wed, Sep 30, 2009 at 4:14 PM, Markus Moll <markus.moll@xxxxxxxxxxxxxxxx> wrote:
Hi

Another alternative is having a templated constructor which is a better match
for types other than T:

template<typename T, [...]>
class Replicate
{
       [...]

       template<typename U> struct dummy;

       Replicate(const T& t);
       template<typename U> Replicate(const U& u) { dummy<U>::template
ConstructionOnlyPossibleFromType<T>; }

       [...]
};

int main()
{
       SomeClass obj;
       Replicate<SomeOtherClass> r( obj );
}

Here, gcc emits an error like:
: In constructor ‘X<T>::X(const U&) [with U = SomeClass, T = SomeOtherClass]’:
:  instantiated from here
: error: ‘ConstructionOnlyPossibleFrom<T>’ is not a member of
               ‘X<SomeOtherClass>::dummy<SomeClass>’

Does anyone see any problem with either of these approaches?
If not, I guess it's a matter of taste.
Personally, I think the solution posted earlier is cleaner.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/