From b8d73731779bce53e940e347e71851d45c9c6cdc Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Fri, 21 Feb 2014 21:00:38 +0100 Subject: [PATCH] arrays : fix auto_assign for chains assignment. A(i_)(om_) << ... for A an array of gf was not working. Modified the auto_assign of arrays to handle the case when the object in the array is itself autoassigned. Using the model of std::vector adapter for clef, which works. Also fixed the gf for a little details (gf_impl is usually in the expression tree, not gf). --- triqs/arrays/impl/indexmap_storage_pair.hpp | 19 ++++++++++++++++++- triqs/gfs/gf.hpp | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/triqs/arrays/impl/indexmap_storage_pair.hpp b/triqs/arrays/impl/indexmap_storage_pair.hpp index 0cc80e98..5bc3c7a2 100644 --- a/triqs/arrays/impl/indexmap_storage_pair.hpp +++ b/triqs/arrays/impl/indexmap_storage_pair.hpp @@ -260,7 +260,24 @@ namespace triqs { namespace arrays { return make_expr_call(std::move(*this),args...); } - template friend void triqs_clef_auto_assign (indexmap_storage_pair & x, Fnt f) { assign_foreach(x,f);} + // ------------------------------- clef auto assign -------------------------------------------- + + // For simple cases, it is assign_foreach. But when f(args...) is a function from a clef expression + // we make a chain call like cf clef vector adapter + template struct _worker { + indexmap_storage_pair &A; + Function const &f; + template void assign(T &x, RHS &&rhs) { x = std::forward(rhs); } + template void assign(T &x, clef::make_fun_impl &&rhs) { + triqs_clef_auto_assign(x, std::forward>(rhs)); + } + template void operator()(Args const &... args) { this->assign(A(args...), f(args...)); } + }; + + template friend void triqs_clef_auto_assign(indexmap_storage_pair &x, Fnt f) { + foreach(x, _worker{x, f}); + } + // template friend void triqs_clef_auto_assign (indexmap_storage_pair & x, Fnt f) { assign_foreach(x,f);} // ------------------------------- Iterators -------------------------------------------- typedef iterator_adapter const_iterator; diff --git a/triqs/gfs/gf.hpp b/triqs/gfs/gf.hpp index a995f222..9545524a 100644 --- a/triqs/gfs/gf.hpp +++ b/triqs/gfs/gf.hpp @@ -431,6 +431,15 @@ namespace gfs { } }; + // in most expression, the gf_impl version is enough. + // But in chained clef expression, A(i_)(om_) where A is an array of gf + // we need to call it with the gf, not gf_impl (or the template resolution find the deleted funciton in clef). + // Another fix is to make gf, gf_view in the expression tree, but this requires using CRPT in gf_impl... + template + void triqs_clef_auto_assign(gf &g, RHS const &rhs) { + triqs_clef_auto_assign( static_cast&>(g), rhs); + } + // --------------------------The const View class of GF ------------------------------------------------------- template