The Battle for Wesnoth  1.19.19+dev
ranges.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 - 2025
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 #pragma once
16 
17 #ifdef __cpp_lib_ranges
18 #include <ranges>
19 #else
20 #include <boost/range/adaptor/filtered.hpp>
21 #include <boost/range/adaptor/map.hpp>
22 #include <boost/range/adaptor/reversed.hpp>
23 #include <boost/range/adaptor/transformed.hpp>
24 #endif
25 
26 #ifndef __cpp_lib_ranges_stride
27 #include <boost/range/adaptor/strided.hpp>
28 #endif
29 
30 namespace utils::views
31 {
32 #ifdef __cpp_lib_ranges
33 
34 using std::views::filter;
35 using std::views::keys;
38 using std::views::values;
39 
40 #else
41 
42 constexpr auto filter = boost::adaptors::filtered;
43 constexpr auto keys = boost::adaptors::map_keys;
44 constexpr auto reverse = boost::adaptors::reversed;
45 constexpr auto transform = boost::adaptors::transformed;
46 constexpr auto values = boost::adaptors::map_values;
47 
48 #endif
49 
50 //
51 // Ranges introduced in C++23
52 //
53 
54 #ifdef __cpp_lib_ranges_stride
55 using std::views::stride;
56 #else
57 constexpr auto stride = boost::adaptors::strided;
58 #endif
59 
60 } // namespace utils::views
constexpr auto stride
Definition: ranges.hpp:57
constexpr auto transform
Definition: ranges.hpp:45
constexpr auto values
Definition: ranges.hpp:46
constexpr auto reverse
Definition: ranges.hpp:44
constexpr auto keys
Definition: ranges.hpp:43
constexpr auto filter
Definition: ranges.hpp:42