diff --git a/triqs/gfs/meshes/mesh_tools.hpp b/triqs/gfs/meshes/mesh_tools.hpp index 80ad1445..fae3dc75 100644 --- a/triqs/gfs/meshes/mesh_tools.hpp +++ b/triqs/gfs/meshes/mesh_tools.hpp @@ -22,20 +22,31 @@ #define TRIQS_GF_MESHTOOLS_H #include "../tools.hpp" -namespace triqs { namespace gfs { +namespace triqs { +namespace gfs { - // Derive from this object using CRTP to provide arithmetic operation by casting the final object to C - template struct arith_ops_by_cast {}; -#define IMPL_OP(OP)\ - template \ - auto operator OP(arith_ops_by_cast const & x, T const & y) -> decltype( std::declval() OP y) {return C(static_cast(x)) OP y;}\ - template \ - auto operator OP( T const & y, arith_ops_by_cast const & x) -> TYPE_DISABLE_IF(decltype (y OP std::declval()), std::is_same) {return y OP C(static_cast(x));} - IMPL_OP(+); IMPL_OP(-); IMPL_OP(*); IMPL_OP(/); + // Derive from this object using CRTP to provide arithmetic operation by casting the final object to C + // by not forwarding x, I assume the cast is a simple value, not a matrix, but this is ok + template struct arith_ops_by_cast {}; + +#define IMPL_OP(OP) \ + template \ + auto operator OP(arith_ops_by_cast const& x, Y&& y)->decltype(std::declval() OP std::forward(y)) { \ + return C(static_cast(x)) OP std::forward(y); \ + } \ + template \ + auto operator OP(Y&& y, arith_ops_by_cast const& x) \ + ->TYPE_DISABLE_IF(decltype(std::forward(y) OP std::declval()), \ + std::is_same::type>::type, D>) { \ + return std::forward(y) OP C(static_cast(x)); \ + } + + IMPL_OP(+); + IMPL_OP(-); + IMPL_OP(*); + IMPL_OP(/ ); #undef IMPL_OP - - //TYPE_DISABLE_IF(decltype (std::declval() OP std::declval()), std::is_same)\ - //operator OP( T const & y, arith_ops_by_cast const & x) {return y OP C(static_cast(x));} + //------------------------------------------------------