mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
refactor: make namespace ranges
mostly an alias of std::ranges
This commit is contained in:
parent
4717fe8045
commit
0577b4d9de
@ -5,40 +5,20 @@
|
|||||||
#ifndef BITCOIN_UTIL_RANGES_H
|
#ifndef BITCOIN_UTIL_RANGES_H
|
||||||
#define BITCOIN_UTIL_RANGES_H
|
#define BITCOIN_UTIL_RANGES_H
|
||||||
|
|
||||||
#include <algorithm>
|
#include <ranges>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
//#if __cplusplus > 201703L // C++20 compiler
|
|
||||||
//namespace ranges = std::ranges;
|
|
||||||
//#else
|
|
||||||
|
|
||||||
#define MK_RANGE(FUN) \
|
|
||||||
template <typename X, typename Z> \
|
|
||||||
inline auto FUN(const X& ds, const Z& fn) { \
|
|
||||||
return std::FUN(cbegin(ds), cend(ds), fn); \
|
|
||||||
} \
|
|
||||||
template <typename X, typename Z> \
|
|
||||||
inline auto FUN(X& ds, const Z& fn) { \
|
|
||||||
return std::FUN(begin(ds), end(ds), fn); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace ranges {
|
namespace ranges {
|
||||||
MK_RANGE(all_of)
|
using namespace std::ranges;
|
||||||
MK_RANGE(any_of)
|
|
||||||
MK_RANGE(count_if)
|
|
||||||
MK_RANGE(find_if)
|
|
||||||
|
|
||||||
template <typename X, typename Z>
|
template <typename X, typename Z>
|
||||||
constexpr inline auto find_if_opt(const X& ds, const Z& fn) {
|
constexpr inline auto find_if_opt(const X& ds, const Z& fn) {
|
||||||
const auto it = ranges::find_if(ds, fn);
|
const auto it = std::ranges::find_if(ds, fn);
|
||||||
if (it != end(ds)) {
|
if (it != std::end(ds)) {
|
||||||
return std::make_optional(*it);
|
return std::make_optional(*it);
|
||||||
}
|
|
||||||
return std::optional<std::decay_t<decltype(*it)>>{};
|
|
||||||
}
|
}
|
||||||
|
return std::optional<std::decay_t<decltype(*it)>>{};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endif // C++20 compiler
|
|
||||||
#endif // BITCOIN_UTIL_RANGES_H
|
#endif // BITCOIN_UTIL_RANGES_H
|
||||||
|
Loading…
Reference in New Issue
Block a user