Cupt
range.hpp
1 /**************************************************************************
2 * Copyright (C) 2013 by Eugene V. Lyubimkin *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License *
6 * (version 3 or above) as published by the Free Software Foundation. *
7 * *
8 * This program is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11 * GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU GPL *
14 * along with this program; if not, write to the *
15 * Free Software Foundation, Inc., *
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
17 **************************************************************************/
18 #ifndef CUPT_RANGE_SEEN
19 #define CUPT_RANGE_SEEN
20 
21 #include <utility>
22 #include <vector>
23 
24 namespace cupt {
25 
26 template < typename IteratorT >
27 struct Range: public std::pair< IteratorT, IteratorT >
28 {
29  typedef std::pair< IteratorT, IteratorT > Base;
30 
31  Range()
32  {}
33  Range(const IteratorT& from, const IteratorT& to)
34  : Base(from, to)
35  {}
36 
37  IteratorT begin() const
38  {
39  return Base::first;
40  }
41  IteratorT end() const
42  {
43  return Base::second;
44  }
45  typedef typename std::decay<decltype(*std::declval<IteratorT>())>::type Value;
46  auto asVector() const -> std::vector< Value >
47  {
48  std::vector< Value > result;
49  for (const auto& element: *this)
50  {
51  result.push_back(element);
52  }
53  return result;
54  }
55 
56  typedef IteratorT Iterator;
57 };
58 
59 }
60 
61 #endif
62