The Battle for Wesnoth  1.19.0-dev
iterable_pair.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * Enable range-for iteration over pairs of iterators.
18  */
19 
20 #pragma once
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 }
std::reverse_iterator< T > crend(const std::pair< T, T > &p)
T cend(const std::pair< T, T > &p)
std::reverse_iterator< T > rbegin(const std::pair< T, T > &p)
T end(const std::pair< T, T > &p)
T begin(const std::pair< T, T > &p)
std::reverse_iterator< T > rend(const std::pair< T, T > &p)
std::reverse_iterator< T > crbegin(const std::pair< T, T > &p)
T cbegin(const std::pair< T, T > &p)
mock_party p