From a5938a8d9e827934a2b56b044e08a85ca53266bb Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Fri, 18 Oct 2013 20:20:07 +0200 Subject: [PATCH] Fix arithmetic of mesh_points in gf - the arithmetics of the gf mesh_points : the forwarding of the second argument was missing, leading to subtle bugs e.g. in (in matrix case) : deltaw(iom_) << iom_ * gw.singularity()(-1) + gw.singularity()(0) - gw(iom_); because the partial evaluation of the expression introduced a dangling const matrix_view & instead of moving the temporary matrix_view into the final matrix expression template. --- triqs/gfs/meshes/mesh_tools.hpp | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) 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));} + //------------------------------------------------------