Template constructor parameter base type check in C++

38 Views Asked by At

Im trying to write some simple math libary in C++ using Expression templates.

template <typename E1, typename E2>
class MatSum : public MatExpression<MatSum<E1, E2>> {
E1 const& _u;
E2 const& _v;
public:
MatSum(E1 const& u, E2 const& v) :_u(u), _v(v) {
    assert(u.size() == v.size());
}

GLfloat operator[](size_t i) const { return _u[i] + _v[i]; }
GLfloat operator()(size_t i, size_t j) const { return _u(i,j) + _v(i,j); }
size_t size() const { return _v.size(); }
size_t width() const { return _v.width(); }
size_t height() const { return _v.height(); }
};

How can i make a construtor to check types. I need 3 constructors.

  1. Both are MatExpression
  2. 1st is MatExpression, 2nd is Scalar
  3. 1st is scalar and 2nd is MatExpression

I understand that i need to use type_traits, but i dont understand how to use them.

0

There are 0 best solutions below