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

[ Thread Index | Date Index | More Archives ]

On Wed, Sep 30, 2009 at 4:52 PM, Markus Moll <markus.moll@xxxxxxxxxxxxxxxx> wrote:
Hm, what was the third solution?

In theory we could prevent implicit conversion by making the Matrix ctors explicit, i.e.

explicit Matrix(const MatrixBase<OtherDerived>& other);
explicit Matrix(const AnyMatrixBase<OtherDerived> &other);

But it is probably not really a solution since it seems that we rely on implicit conversions.
Also, what solution do you refer to as the second solution?

The same as you do, the additional ctor approach.
The reason why I like the first solution better is that it does not add any
constructors. There's one major benefit, consider:

       Replicate<MatrixXd::RowXpr,2,1> rep(5);

Here, the compiler won't find a suitable constructor and will probably list
the set of candidates. That might be very helpful. With the second approach, a
suitable constructor *is* found, but instantiation leads to an unusual compile

With static asserts we can make the compile error self explanatory. I preferred the ctor approach since it does not require implementing a ConstRef class.


Mail converted by MHonArc 2.6.19+