|
5 | 5 | #ifndef BITCOIN_UTIL_RANGES_H |
6 | 6 | #define BITCOIN_UTIL_RANGES_H |
7 | 7 |
|
8 | | -#include <algorithm> |
9 | 8 | #include <optional> |
10 | | - |
11 | | -//#if __cplusplus > 201703L // C++20 compiler |
12 | | -//namespace ranges = std::ranges; |
13 | | -//#else |
14 | | - |
15 | | -#define MK_RANGE(FUN) \ |
16 | | -template <typename X, typename Z> \ |
17 | | -inline auto FUN(const X& ds, const Z& fn) { \ |
18 | | - return std::FUN(cbegin(ds), cend(ds), fn); \ |
19 | | -} \ |
20 | | -template <typename X, typename Z> \ |
21 | | -inline auto FUN(X& ds, const Z& fn) { \ |
22 | | - return std::FUN(begin(ds), end(ds), fn); \ |
23 | | -} |
24 | | - |
| 9 | +#include <ranges> |
25 | 10 |
|
26 | 11 | namespace ranges { |
27 | | - MK_RANGE(all_of) |
28 | | - MK_RANGE(any_of) |
29 | | - MK_RANGE(count_if) |
30 | | - MK_RANGE(find_if) |
31 | | - |
32 | | - template <typename X, typename Z> |
33 | | - constexpr inline auto find_if_opt(const X& ds, const Z& fn) { |
34 | | - const auto it = ranges::find_if(ds, fn); |
35 | | - if (it != end(ds)) { |
36 | | - return std::make_optional(*it); |
37 | | - } |
38 | | - return std::optional<std::decay_t<decltype(*it)>>{}; |
| 12 | +using namespace std::ranges; |
| 13 | + |
| 14 | +template <typename X, typename Z> |
| 15 | +constexpr inline auto find_if_opt(const X& ds, const Z& fn) |
| 16 | +{ |
| 17 | + const auto it = std::ranges::find_if(ds, fn); |
| 18 | + if (it != std::end(ds)) { |
| 19 | + return std::make_optional(*it); |
39 | 20 | } |
40 | | - |
| 21 | + return std::optional<std::decay_t<decltype(*it)>>{}; |
| 22 | +} |
41 | 23 | } |
42 | 24 |
|
43 | | -//#endif // C++20 compiler |
44 | 25 | #endif // BITCOIN_UTIL_RANGES_H |
0 commit comments