The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
iterable_pair.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13  */
14 
15 /**
16  * @file Enable range-for iteration over pairs of iterators.
17  */
18 
19 #ifndef UTILS_ITERABLE_PAIR_HPP_INCLUDED
20 #define UTILS_ITERABLE_PAIR_HPP_INCLUDED
21 
22 #include <utility>
23 #include <iterator>
24 
25 namespace std { // Some cases don't work if not in std namespace
26 
27 template<typename T>
28 inline T begin(const std::pair<T, T>& p) {
29  return p.first;
30 }
31 
32 template<typename T>
33 inline T end(const std::pair<T, T>& p) {
34  return p.second;
35 }
36 
37 // TODO: Is there a way to enforce that this is called only for const_iterators?
38 template<typename T>
39 inline T cbegin(const std::pair<T, T>& p) {
40  return p.first;
41 }
42 
43 template<typename T>
44 inline T cend(const std::pair<T, T>& p) {
45  return p.second;
46 }
47 
48 template<typename T>
49 inline std::reverse_iterator<T> rbegin(const std::pair<T, T>& p) {
50  return std::reverse_iterator<T>(p.second);
51 }
52 
53 template<typename T>
54 inline std::reverse_iterator<T> rend(const std::pair<T, T>& p) {
55  return std::reverse_iterator<T>(p.first);
56 }
57 
58 // TODO: Is there a way to enforce that this is called only for const_iterators?
59 template<typename T>
60 inline std::reverse_iterator<T> crbegin(const std::pair<T, T>& p) {
61  return std::reverse_iterator<T>(p.second);
62 }
63 
64 template<typename T>
65 inline std::reverse_iterator<T> crend(const std::pair<T, T>& p) {
66  return std::reverse_iterator<T>(p.first);
67 }
68 
69 }
70 
71 #endif
STL namespace.
GLuint GLuint end
Definition: glew.h:1221
GLfloat GLfloat p
Definition: glew.h:12766