3
0
mirror of https://github.com/triqs/dft_tools synced 2024-10-31 19:23:45 +01:00

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).
This commit is contained in:
Olivier Parcollet 2014-02-21 21:00:38 +01:00
parent 3d98857c13
commit b8d7373177
2 changed files with 27 additions and 1 deletions

View File

@ -260,7 +260,24 @@ namespace triqs { namespace arrays {
return make_expr_call(std::move(*this),args...);
}
template<typename Fnt> 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 <typename Function> struct _worker {
indexmap_storage_pair &A;
Function const &f;
template <typename T, typename RHS> void assign(T &x, RHS &&rhs) { x = std::forward<RHS>(rhs); }
template <typename Expr, int... Is, typename T> void assign(T &x, clef::make_fun_impl<Expr, Is...> &&rhs) {
triqs_clef_auto_assign(x, std::forward<clef::make_fun_impl<Expr, Is...>>(rhs));
}
template <typename... Args> void operator()(Args const &... args) { this->assign(A(args...), f(args...)); }
};
template <typename Fnt> friend void triqs_clef_auto_assign(indexmap_storage_pair &x, Fnt f) {
foreach(x, _worker<Fnt>{x, f});
}
// template<typename Fnt> friend void triqs_clef_auto_assign (indexmap_storage_pair & x, Fnt f) { assign_foreach(x,f);}
// ------------------------------- Iterators --------------------------------------------
typedef iterator_adapter<true,typename IndexMapType::iterator, StorageType> const_iterator;

View File

@ -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 <typename RHS, typename Variable, typename Target, typename Opt>
void triqs_clef_auto_assign(gf<Variable, Target, Opt> &g, RHS const &rhs) {
triqs_clef_auto_assign( static_cast<gf_impl<Variable, Target, Opt, false, false>&>(g), rhs);
}
// --------------------------The const View class of GF -------------------------------------------------------
template <typename Variable, typename Target, typename Opt>