The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
iterable_pair.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2014 - 2025
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
25namespace std { // Some cases don't work if not in std namespace
26
27template<typename T>
28inline T begin(const std::pair<T, T>& p) {
29 return p.first;
30}
31
32template<typename T>
33inline 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?
38template<typename T>
39inline T cbegin(const std::pair<T, T>& p) {
40 return p.first;
41}
42
43template<typename T>
44inline T cend(const std::pair<T, T>& p) {
45 return p.second;
46}
47
48template<typename T>
49inline std::reverse_iterator<T> rbegin(const std::pair<T, T>& p) {
50 return std::reverse_iterator<T>(p.second);
51}
52
53template<typename T>
54inline 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?
59template<typename T>
60inline std::reverse_iterator<T> crbegin(const std::pair<T, T>& p) {
61 return std::reverse_iterator<T>(p.second);
62}
63
64template<typename T>
65inline std::reverse_iterator<T> crend(const std::pair<T, T>& p) {
66 return std::reverse_iterator<T>(p.first);
67}
68
69}
STL namespace.
T cend(const std::pair< T, T > &p)
std::reverse_iterator< T > crend(const std::pair< T, T > &p)
std::reverse_iterator< T > rbegin(const std::pair< T, T > &p)
std::reverse_iterator< T > rend(const std::pair< T, T > &p)
T end(const std::pair< T, T > &p)
T begin(const std::pair< T, T > &p)
T cbegin(const std::pair< T, T > &p)
std::reverse_iterator< T > crbegin(const std::pair< T, T > &p)
mock_party p