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 #include <utility>
19 #include <vector>
20 
21 namespace cupt {
22 
23 template < typename IteratorT >
24 struct Range: public std::pair< IteratorT, IteratorT >
25 {
26  typedef std::pair< IteratorT, IteratorT > Base;
27  Range(const IteratorT& from, const IteratorT& to)
28  : Base(from, to)
29  {}
30  IteratorT begin() const
31  {
32  return Base::first;
33  }
34  IteratorT end() const
35  {
36  return Base::second;
37  }
38  typedef typename std::decay<typename IteratorT::value_type>::type Value;
39  auto asVector() const -> std::vector< Value >
40  {
41  vector< Value > result;
42  for (const auto& element: *this)
43  {
44  result.push_back(element);
45  }
46  return result;
47  }
48 };
49 
50 }
51