# Support for custom scalar types with expression templates in numext

## @ggael

Submitted by Gael GuennebaudAssigned to **Nobody**

**Link to original bugzilla bug (#1257)**

**Version**: 3.3 (current stable)

## Description

Created attachment 717

proof of concept for the c++14 auto approach.

Currently, our numext wrappers/helpers does not play well with scalar types implementing expression templates. A typical exemple is boost::multiprecision that you can try by modifying et_off to et_on in test/boostmultiprec.cpp. The problem is in calls such as:

Scalar x;

numext::sqrt(abs(x))

numext::sqrt(2*x)

because the prototype of numext::sqrt is:

template<typename T> T sqrt(const T&);

and in the previous example abs(x) or 2*x return an expression.

For Eigen's types and some numext functions (like abs), we workaround the issue with some complicated mechanism to specialize the return type for Eigen's type. But this cannot scale to arbitrary scalar types.

I see tow solutions:

1 - explicitely tell the desired scalar type to any calls to numext::foo, e.g., the above example would become:

numext::sqrt<Scalar>(2*x);

this disabling expression template also for Eigen's Array/Matrix as scalar type.

2 - enable support for ET for C++14 only by defining the return type of all numext method with 'auto'. See the attached patch for a proof of concept. This approach is not perfect yet. For instance, we cannot fully apply it to maxi/mini for which both arguments must have the same type to make sure we can call the std:: versions.

**Patch 717**, "proof of concept for the c++14 auto approach.":

support_for_ET_with_cxx14_auto.diff