3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 13:53:40 +01:00

gf: draft of iterator on gf blocks ...

- to be completed
- missing cbegin et al, pb with for(auto & g : ...)
because it returns a view...
This commit is contained in:
Olivier Parcollet 2013-07-27 15:06:10 +02:00
parent 893736dbbf
commit 37f861b0b5
3 changed files with 34 additions and 1 deletions

View File

@ -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;}
}

View File

@ -131,6 +131,34 @@ namespace triqs { namespace gf {
template<typename Target, typename ... U>
gf<block_index, gf<Target>> make_block_gf(U && ...u) { return gf_implementation::factories<block_index,gf<Target>,void>::make_gf(std::forward<U>(u)...);}
// also experimental
// an iterator over the block
template<typename Target, typename Opt>
class block_gf_iterator :
public boost::iterator_facade< block_gf_iterator<Target,Opt>, typename Target::view_type , boost::forward_traversal_tag, typename Target::view_type > {
friend class boost::iterator_core_access;
typedef gf_view<block_index,Target,Opt> 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<block_index,Target,Opt> 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<typename Target, typename Opt, bool B>
block_gf_iterator<Target,Opt> begin(gf_impl<block_index,Target,Opt,B> const & bgf) { return {bgf,false};}
template<typename Target, typename Opt, bool B>
block_gf_iterator<Target,Opt> end(gf_impl<block_index,Target,Opt,B> const & bgf) { return {bgf,true};}
}}
#endif

View File

@ -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(); }