The Battle for Wesnoth  1.15.1+dev
iterable_pair.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
20 
21 #include <utility>
22 #include <iterator>
23 
24 namespace std { // Some cases don't work if not in std namespace
25 
26 template<typename T>
27 inline T begin(const std::pair<T, T>& p) {
28  return p.first;
29 }
30 
31 template<typename T>
32 inline T end(const std::pair<T, T>& p) {
33  return p.second;
34 }
35 
36 // TODO: Is there a way to enforce that this is called only for const_iterators?
37 template<typename T>
38 inline T cbegin(const std::pair<T, T>& p) {
39  return p.first;
40 }
41 
42 template<typename T>
43 inline T cend(const std::pair<T, T>& p) {
44  return p.second;
45 }
46 
47 template<typename T>
48 inline std::reverse_iterator<T> rbegin(const std::pair<T, T>& p) {
49  return std::reverse_iterator<T>(p.second);
50 }
51 
52 template<typename T>
53 inline std::reverse_iterator<T> rend(const std::pair<T, T>& p) {
54  return std::reverse_iterator<T>(p.first);
55 }
56 
57 // TODO: Is there a way to enforce that this is called only for const_iterators?
58 template<typename T>
59 inline std::reverse_iterator<T> crbegin(const std::pair<T, T>& p) {
60  return std::reverse_iterator<T>(p.second);
61 }
62 
63 template<typename T>
64 inline std::reverse_iterator<T> crend(const std::pair<T, T>& p) {
65  return std::reverse_iterator<T>(p.first);
66 }
67 
68 }
std::reverse_iterator< T > crbegin(const std::pair< T, T > &p)
STL namespace.
std::reverse_iterator< T > rbegin(const std::pair< T, T > &p)
T end(const std::pair< T, T > &p)
std::reverse_iterator< T > crend(const std::pair< T, T > &p)
mock_party p
T cend(const std::pair< T, T > &p)
std::reverse_iterator< T > rend(const std::pair< T, T > &p)
T cbegin(const std::pair< T, T > &p)
T begin(const std::pair< T, T > &p)