Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Range.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This file is part of the gobelijn software.
4  * Gobelijn is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or any later
7  * version. Gobelijn is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9  * or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for details. You should have received
11  * a copy of the GNU General Public License along with the software. If not,
12  * see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2012, Jan Broeckhove, CoMP/UA.
15  */
21 // BEGIN_SNIPPET{FullSource}
22 #include <iostream>
23 
27 template <typename Iter>
28 struct Range : public std::pair<Iter, Iter>
29 {
30  Range(Iter it1, Iter it2) : std::pair<Iter, Iter>(it1, it2){};
31 };
32 
33 template <typename Iter>
34 Range<Iter> make_range(Iter it1, Iter it2)
35 {
36  return Range<Iter>(it1, it2);
37 }
38 
39 template <typename Cont>
41 {
42  return Range<typename Cont::const_iterator>(c.begin(), c.end());
43 }
44 
45 template <typename T, typename U>
46 std::ostream& operator<<(std::ostream& out, std::pair<T, U> const& p)
47 {
48  operator<<(out.operator<<(p.first), " - ");
49  (out.operator<<(p.second)).operator<<(std::endl);
50  return out;
51 }
52 
53 template <typename Iter>
54 std::ostream& operator<<(std::ostream& out, Range<Iter> r)
55 {
56  for (Iter it = r.first; it != r.second; ++it) {
57  out << " " << *it;
58  }
59  return out;
60 }
61 // END_SNIPPET{FullSource}
std::ostream & operator<<(std::ostream &out, std::pair< T, U > const &p)
Definition: Range.h:46
Range(Iter it1, Iter it2)
Definition: Range.h:30
Range needs to be a specific type so we can overload some operators (e.g.
Definition: Range.h:28
Range< Iter > make_range(Iter it1, Iter it2)
Definition: Range.h:34