mirror of
https://github.com/triqs/dft_tools
synced 2024-10-31 19:23:45 +01:00
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.
This commit is contained in:
parent
7419b1a68e
commit
a5938a8d9e
@ -22,20 +22,31 @@
|
|||||||
#define TRIQS_GF_MESHTOOLS_H
|
#define TRIQS_GF_MESHTOOLS_H
|
||||||
#include "../tools.hpp"
|
#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
|
// Derive from this object using CRTP to provide arithmetic operation by casting the final object to C
|
||||||
template<typename Derived, typename C> struct arith_ops_by_cast {};
|
// by not forwarding x, I assume the cast is a simple value, not a matrix, but this is ok
|
||||||
#define IMPL_OP(OP)\
|
template <typename Derived, typename C> struct arith_ops_by_cast {};
|
||||||
template<typename D, typename C, typename T> \
|
|
||||||
auto operator OP(arith_ops_by_cast<D,C> const & x, T const & y) -> decltype( std::declval<C>() OP y) {return C(static_cast<D const& >(x)) OP y;}\
|
#define IMPL_OP(OP) \
|
||||||
template<typename D, typename C, typename T> \
|
template <typename D, typename C, typename Y> \
|
||||||
auto operator OP( T const & y, arith_ops_by_cast<D,C> const & x) -> TYPE_DISABLE_IF(decltype (y OP std::declval<C>()), std::is_same<T,D>) {return y OP C(static_cast<D const& >(x));}
|
auto operator OP(arith_ops_by_cast<D, C> const& x, Y&& y)->decltype(std::declval<C>() OP std::forward<Y>(y)) { \
|
||||||
IMPL_OP(+); IMPL_OP(-); IMPL_OP(*); IMPL_OP(/);
|
return C(static_cast<D const&>(x)) OP std::forward<Y>(y); \
|
||||||
|
} \
|
||||||
|
template <typename D, typename C, typename Y> \
|
||||||
|
auto operator OP(Y&& y, arith_ops_by_cast<D, C> const& x) \
|
||||||
|
->TYPE_DISABLE_IF(decltype(std::forward<Y>(y) OP std::declval<C>()), \
|
||||||
|
std::is_same<typename std::remove_cv<typename std::remove_reference<Y>::type>::type, D>) { \
|
||||||
|
return std::forward<Y>(y) OP C(static_cast<D const&>(x)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPL_OP(+);
|
||||||
|
IMPL_OP(-);
|
||||||
|
IMPL_OP(*);
|
||||||
|
IMPL_OP(/ );
|
||||||
#undef IMPL_OP
|
#undef IMPL_OP
|
||||||
|
|
||||||
//TYPE_DISABLE_IF(decltype (std::declval<T>() OP std::declval<C>()), std::is_same<T,D>)\
|
|
||||||
//operator OP( T const & y, arith_ops_by_cast<D,C> const & x) {return y OP C(static_cast<D const& >(x));}
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user