From de0e41ed15f6d67821ef6c586e8599d0fbc9597c Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Mon, 21 Oct 2013 21:53:17 +0200 Subject: [PATCH] gf: finish block iterator --- test/triqs/gfs/block.cpp | 6 +++-- triqs/gfs/block.hpp | 50 ++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/test/triqs/gfs/block.cpp b/test/triqs/gfs/block.cpp index 24980803..814d32a6 100644 --- a/test/triqs/gfs/block.cpp +++ b/test/triqs/gfs/block.cpp @@ -12,7 +12,8 @@ int main() { auto G3 = G2; // construct some block functions - auto B0 = block_gf (3); + auto B0 = block_gf (3); + auto B1 = make_block_gf (3, G1); auto B2 = make_block_gf ({G1,G1,G1}); auto B3 = make_block_gf ({"a","b","c"}, {G1,G1,G1}); @@ -57,7 +58,8 @@ int main() { TEST( View[0](0) ) ; // try the loop over the block. - for (auto g : View) { g[0] = 20;} + for (auto & g : View) { g[0] = 20;} + for (auto & g : B1) { g[0] = 20;} } TRIQS_CATCH_AND_ABORT; diff --git a/triqs/gfs/block.hpp b/triqs/gfs/block.hpp index cce918f4..8dde72d1 100644 --- a/triqs/gfs/block.hpp +++ b/triqs/gfs/block.hpp @@ -164,74 +164,74 @@ namespace triqs { namespace gfs { // ------------------------------- an iterator over the blocks -------------------------------------------------- // iterator - template - class block_gf_iterator : public boost::iterator_facade, typename Target::view_type, - boost::forward_traversal_tag, typename Target::view_type> { + template + class block_gf_iterator + : public boost::iterator_facade, Target, boost::forward_traversal_tag, Target &> { friend class boost::iterator_core_access; - typedef gf_view big_gf_t; + typedef gf_impl big_gf_t; + big_gf_t & big_gf; typedef typename big_gf_t::mesh_t::const_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]; } + Target &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) {} + block_gf_iterator(big_gf_t & bgf, bool at_end = false) + : big_gf(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 &bgf) { + block_gf_iterator begin(gf_impl &bgf) { return {bgf, false}; } - //------------ + //------------ template - block_gf_iterator end(gf_impl &bgf) { + block_gf_iterator end(gf_impl &bgf) { return {bgf, true}; } - //----- const iterator - template - class block_gf_const_iterator : public boost::iterator_facade, typename Target::const_view_type, - boost::forward_traversal_tag, typename Target::const_view_type> { + //----- const iterator + template + class block_gf_const_iterator + : public boost::iterator_facade, Target, boost::forward_traversal_tag, Target const &> { friend class boost::iterator_core_access; - typedef gf_const_view big_gf_t; + typedef gf_impl big_gf_t; + big_gf_t const & big_gf; typedef typename big_gf_t::mesh_t::const_iterator mesh_iterator_t; - big_gf_t big_gf; mesh_iterator_t mesh_it; - typename Target::const_view_type const &dereference() const { return big_gf[*mesh_it]; } + Target const &dereference() const { return big_gf[*mesh_it]; } bool equal(block_gf_const_iterator const &other) const { return ((mesh_it == other.mesh_it)); } public: - block_gf_const_iterator(gf_const_view bgf, bool at_end = false) - : big_gf(std::move(bgf)), mesh_it(&big_gf.mesh(), at_end) {} + block_gf_const_iterator(big_gf_t const& bgf, bool at_end = false) + : big_gf(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) { + block_gf_const_iterator begin(gf_impl const &bgf) { return {bgf, false}; } template - block_gf_iterator end(gf_impl const &bgf) { + block_gf_const_iterator end(gf_impl const &bgf) { return {bgf, true}; } template - block_gf_iterator cbegin(gf_impl const &bgf) { + block_gf_const_iterator cbegin(gf_impl const &bgf) { return {bgf, false}; } template - block_gf_iterator cend(gf_impl const &bgf) { + block_gf_const_iterator cend(gf_impl const &bgf) { return {bgf, true}; }