diff --git a/test/triqs/gf/block.cpp b/test/triqs/gf/block.cpp index a5f2b2dd..9ac6643a 100644 --- a/test/triqs/gf/block.cpp +++ b/test/triqs/gf/block.cpp @@ -75,4 +75,7 @@ int main() { //TEST( g0("3.2") ) ; //TEST( GF(0)(0) ) ; + // try the loop over the block. + for (auto g : GF) { g.on_mesh(0) = 20;} + } diff --git a/triqs/gf/block.hpp b/triqs/gf/block.hpp index 16c0040b..2889bf23 100644 --- a/triqs/gf/block.hpp +++ b/triqs/gf/block.hpp @@ -131,6 +131,34 @@ namespace triqs { namespace gf { template gf> make_block_gf(U && ...u) { return gf_implementation::factories,void>::make_gf(std::forward(u)...);} + // also experimental + // an iterator over the block + template + class block_gf_iterator : + public boost::iterator_facade< block_gf_iterator, typename Target::view_type , boost::forward_traversal_tag, typename Target::view_type > { + friend class boost::iterator_core_access; + typedef gf_view big_gf_t; + typedef typename big_gf_t::mesh_t::iterator mesh_iterator_t; + big_gf_t big_gf; + mesh_iterator_t mesh_it; + + typename Target::view_type const & dereference() const { return big_gf(*mesh_it);} + bool equal(block_gf_iterator const & other) const { return ((mesh_it == other.mesh_it));} + public: + block_gf_iterator(gf_view bgf, bool at_end = false): big_gf(std::move(bgf)), mesh_it(&big_gf.mesh(),at_end) {} + void increment() { ++mesh_it; } + bool at_end() const { return mesh_it.at_end();} + }; + + template + block_gf_iterator begin(gf_impl const & bgf) { return {bgf,false};} + + template + block_gf_iterator end(gf_impl const & bgf) { return {bgf,true};} + + + + }} #endif diff --git a/triqs/gf/meshes/mesh_tools.hpp b/triqs/gf/meshes/mesh_tools.hpp index 2a9cabaf..995c0c29 100644 --- a/triqs/gf/meshes/mesh_tools.hpp +++ b/triqs/gf/meshes/mesh_tools.hpp @@ -48,7 +48,9 @@ namespace triqs { namespace gf { size_t u; typename MeshType::mesh_point_t pt; typename MeshType::mesh_point_t const & dereference() const { return pt;} - bool equal(mesh_pt_generator const & other) const { return ((mesh == other.mesh) && (other.u==u) );} + bool equal(mesh_pt_generator const & other) const { return ((other.u==u) );} + // do NOT check = of mesh, otherwise e.g. block iterator does not work (infinite loop...) + //bool equal(mesh_pt_generator const & other) const { return ((mesh == other.mesh) && (other.u==u) );} public: mesh_pt_generator( MeshType const * m=NULL, bool atEnd = false): mesh(m), u(atEnd ? m->size(): 0), pt((*m)[typename MeshType::index_t()]) {} void increment() { ++u; pt.advance(); }