Cadabra
Computer algebra system for field theory problems
IndexIterator.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "Storage.hh"
5 #include "Props.hh"
6 
7 namespace cadabra {
8 
15 
16  class index_iterator : public Ex::iterator_base {
17  public:
18  index_iterator(const Properties&);
20 
21  static index_iterator create(const Properties&, const iterator_base&);
22 
23  static index_iterator begin(const Properties&, const iterator_base&, int offset=0);
24  static index_iterator end(const Properties&, const iterator_base&);
25 
27  bool operator==(const index_iterator&) const;
28  bool operator!=(const index_iterator&) const;
31  index_iterator& operator+=(unsigned int);
32 
33  Ex::iterator halt, walk, roof;
34  private:
36 
37  bool is_index(Ex::iterator) const;
38  };
39 
40  struct iter_indices
41  {
42  struct iterator {
44  using difference_type = ptrdiff_t;
46  using const_reference = const value_type&;
47  using pointer = value_type*;
48  using const_pointer = const value_type*;
49  using iterator_category = std::input_iterator_tag;
50 
52 
53  bool operator == (const iterator& other) { return it == other.it; }
54  bool operator != (const iterator& other) { return !(*this == other); }
55  reference operator* () { return it; }
56  pointer operator-> () { return ⁢ }
57  reference operator ++ () { return ++it; }
58  value_type operator ++ (int) { return it++; }
59 
60 
62  };
63 
64  iter_indices(const Properties& properties, Ex::iterator it)
65  : it(it)
66  , properties(properties) { }
67 
69  iterator begin(int offset) { return index_iterator::begin(properties, it, offset); }
71  size_t size() { return std::distance(begin(), end()); }
72 
73  private:
74  Ex::iterator it;
76  };
77  //size_t number_of_indices(const Properties&, Ex::iterator);
78  }
Class holding a collection of properties attached to expressions.
Definition: Props.hh:237
An iterator which iterates over indices even if they are at lower levels, i.e.
Definition: IndexIterator.hh:16
bool is_index(Ex::iterator) const
index_iterator(const Properties &)
Definition: IndexIterator.cc:7
bool operator!=(const index_iterator &) const
Definition: IndexIterator.cc:31
index_iterator operator++(int)
bool operator==(const index_iterator &) const
Definition: IndexIterator.cc:37
index_iterator & operator+=(unsigned int)
Definition: IndexIterator.cc:74
Ex::iterator walk
Definition: IndexIterator.hh:33
static index_iterator end(const Properties &, const iterator_base &)
Definition: IndexIterator.cc:130
static index_iterator create(const Properties &, const iterator_base &)
Definition: IndexIterator.cc:12
static index_iterator begin(const Properties &, const iterator_base &, int offset=0)
Definition: IndexIterator.cc:122
Ex::iterator halt
Definition: IndexIterator.hh:33
const Properties * properties
Definition: IndexIterator.hh:35
Ex::iterator roof
Definition: IndexIterator.hh:33
index_iterator & operator++()
Definition: IndexIterator.cc:84
index_iterator & operator=(const index_iterator &)
Definition: IndexIterator.cc:138
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
Definition: IndexIterator.hh:42
reference operator*()
Definition: IndexIterator.hh:55
pointer operator->()
Definition: IndexIterator.hh:56
ptrdiff_t difference_type
Definition: IndexIterator.hh:44
std::input_iterator_tag iterator_category
Definition: IndexIterator.hh:49
iterator(index_iterator it)
Definition: IndexIterator.hh:51
bool operator==(const iterator &other)
Definition: IndexIterator.hh:53
reference operator++()
Definition: IndexIterator.hh:57
index_iterator it
Definition: IndexIterator.hh:61
bool operator!=(const iterator &other)
Definition: IndexIterator.hh:54
Definition: IndexIterator.hh:41
iterator end()
Definition: IndexIterator.hh:70
Ex::iterator it
Definition: IndexIterator.hh:74
iterator begin()
Definition: IndexIterator.hh:68
iter_indices(const Properties &properties, Ex::iterator it)
Definition: IndexIterator.hh:64
size_t size()
Definition: IndexIterator.hh:71
iterator begin(int offset)
Definition: IndexIterator.hh:69
const Properties & properties
Definition: IndexIterator.hh:75