Skip to content

Commit c4b3dac

Browse files
committed
refactor: make namespace ranges mostly an alias of std::ranges
1 parent a0e133e commit c4b3dac

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

src/util/ranges.h

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,21 @@
55
#ifndef BITCOIN_UTIL_RANGES_H
66
#define BITCOIN_UTIL_RANGES_H
77

8-
#include <algorithm>
98
#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>
2510

2611
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);
3920
}
40-
21+
return std::optional<std::decay_t<decltype(*it)>>{};
22+
}
4123
}
4224

43-
//#endif // C++20 compiler
4425
#endif // BITCOIN_UTIL_RANGES_H

0 commit comments

Comments
 (0)