Re: [eigen] generic argument declaration taking a matrix, vector or expression

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


2012/1/16 Martin Senst <martin.senst@xxxxxx>:
> Am Donnerstag, 12. Januar 2012, 01:24:30 schrieb Benoit Jacob:
>> 2012/1/11 Bernhard Zeisl <bzeisl@xxxxxxxxxxxxxxxx>:
>> > Christoph, thanks a lot for your hint. That solved the problem.
>> >
>> > I agree with you that with the new declaration we lost type safety.
>> > Effectively A, b and x now can be of a different scalar type each.
>> > While it's fine in our case that the function is templated over different
>> > scalar types, it should be required that all arguments are of the same
>> > type. Also it would be nice if that shows up in the interface. As of
>> > now, I guess this is not possible?
>>
>> As Christoph said, the only way to enforce that is by a static
>> assertion, and that won't show up in the interface (if by interface
>> you mean prototype). "Concepts" were supposed to make that possible
>> but they got dropped from c++11, sadly.
>
>
> You could use boost::enable_if to enforce that the scalar types of the
> function parameters match. The following is C++11, but it should be possible
> to make this work in C++03, too:

Do these macros really work? I don't see how they can expand to a
valid function prototype. Anyway, C++03 is what we need to target and
there I don't think it's possible at all to implement enable_if in a
way that doesn't require modifying function prototypes, as I meant
above.

Benoit

>
> #define EIGEN_ENABLE_IF(condition) typename boost::enable_if_c< condition, int
>>::type = 0
>
> #define EIGEN_ENABLE_IF_SAME_SCALAR(T1, T2)
> EIGEN_ENABLE_IF((std::is_same<typename T1::Scalar, typename
> T2::Scalar>::value))
>
> #define EIGEN_ENABLE_IF_SAME_SCALAR3(T1, T2, T3)
> EIGEN_ENABLE_IF((std::is_same<typename T1::Scalar, typename T2::Scalar>::value
> && std::is_same<typename T1::Scalar, typename T3::Scalar>::value))
>
> template <typename T1, typename T2, typename T3,
> EIGEN_ENABLE_IF_SAME_SCALAR3(T1, T2, T3)>
> void f(Eigen::MatrixBase<T1> t1, Eigen::MatrixBase<T2> t2,
> Eigen::MatrixBase<T3> t3);
>
> Cheers,
> Martin
>
>



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