A library for working with phylogenetic and population genetic data.
v0.27.0
range.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_CONTAINERS_RANGE_H_
2 #define GENESIS_UTILS_CONTAINERS_RANGE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2020 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 namespace genesis {
35 namespace utils {
36 
37 // =================================================================================================
38 // Range
39 // =================================================================================================
40 
45 template <typename IteratorType>
46 class Range
47 {
48 public:
49 
50  // -------------------------------------------------------------------------
51  // Member Types
52  // -------------------------------------------------------------------------
53 
54  using iterator = IteratorType;
55 
56  // -------------------------------------------------------------------------
57  // Constructor and Rule of Five
58  // -------------------------------------------------------------------------
59 
60  Range () = default;
61 
62  template <class Container>
63  Range ( Container& cont )
64  : begin_( cont.begin() )
65  , end_( cont.end() )
66  {}
67 
68  template <class Container>
69  Range ( Container const& cont )
70  : begin_( cont.begin() )
71  , end_( cont.end() )
72  {}
73 
75  : begin_(begin)
76  , end_(end)
77  {}
78 
79  Range( Range const& ) = default;
80  Range( Range&& ) = default;
81 
82  Range& operator= ( Range const& ) = default;
83  Range& operator= ( Range&& ) = default;
84 
85  ~Range() = default;
86 
87  // -------------------------------------------------------------------------
88  // Iterators
89  // -------------------------------------------------------------------------
90 
92  {
93  return begin_;
94  }
95 
97  {
98  return end_;
99  }
100 
101  /*
102  const_iterator cbegin()
103  {
104  return RangeIterator<const value_type> (*this);
105  }
106 
107  const_iterator cend()
108  {
109  return RangeIterator<const value_type> (*this, size());
110  }
111  */
112 
113  // -------------------------------------------------------------------------
114  // Element Access
115  // -------------------------------------------------------------------------
116 
117  /*
118  reference operator[] (size_type n)
119  {
120  return *(content_[n]);
121  }
122 
123  const_reference operator[] (size_type n) const
124  {
125  return *(content_[n]);
126  }
127 
128  reference at (size_type n)
129  {
130  return *(content_.at(n));
131  }
132 
133  const_reference at (size_type n) const
134  {
135  return *(content_.at(n));
136  }
137 
138  reference front()
139  {
140  return *(content_.front());
141  }
142 
143  const_reference front() const
144  {
145  return *(content_.front());
146  }
147 
148  reference back()
149  {
150  return *(content_.back());
151  }
152 
153  const_reference back() const
154  {
155  return *(content_.back());
156  }
157  */
158 
159  // -------------------------------------------------------------------------
160  // Data Members
161  // -------------------------------------------------------------------------
162 
163 private:
164 
165  iterator begin_;
166  iterator end_;
167 
168 };
169 
170 } // namespace utils
171 } // namespace genesis
172 
173 #endif // include guard
genesis::utils::Range::begin
iterator begin()
Definition: range.hpp:91
genesis::utils::Range::Range
Range(Container &cont)
Definition: range.hpp:63
genesis::utils::Range::operator=
Range & operator=(Range const &)=default
genesis::utils::Range::Range
Range(iterator begin, iterator end)
Definition: range.hpp:74
genesis::utils::Range
Simple wrapper for typical begin() and end() iterators, to be used in range-based for loops.
Definition: range.hpp:46
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::Range::end
iterator end()
Definition: range.hpp:96
genesis::utils::Range::iterator
IteratorType iterator
Definition: range.hpp:54
genesis::utils::Range::~Range
~Range()=default
genesis::utils::Range::Range
Range()=default
genesis::utils::Range::Range
Range(Container const &cont)
Definition: range.hpp:69