-
Notifications
You must be signed in to change notification settings - Fork 0
/
ranges.hpp
70 lines (51 loc) · 1.58 KB
/
ranges.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#if __clang__
#define MISC_USE_RANGES_RANGE_V3
#else
#define MISC_USE_RANGES_STL
#endif
#ifdef MISC_USE_RANGES_RANGE_V3
#include <range/v3/all.hpp>
namespace misc
{
namespace ranges
{
using namespace ::ranges;
// return type of ::ranges::remove_if is different from which of std::remove_if
struct remove_if_fn
{
template <permutable I, sentinel_for<I> S, typename C, typename P = identity>
constexpr subrange<I>
operator()(I first, S last, C pred, P proj = P{}) const
{
return { ::ranges::remove_if(std::move(first), last, std::move(pred), std::move(proj)), last };
}
template <forward_range Rng, typename C, typename P = identity>
constexpr borrowed_subrange_t<Rng> operator()(Rng&& rng, C pred, P proj = P{}) const
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
};
// this one will be found before ::ranges::remove_if
inline constexpr remove_if_fn remove_if{};
}
// TODO: https://stackoverflow.com/questions/48402558
namespace views = ::ranges::views;
}
#elif defined(MISC_USE_RANGES_STL)
#include <ranges>
namespace misc {
namespace ranges = std::ranges;
namespace views = std::views;
}
#elif defined(MISC_USE_RANGES_BOOST)
#error "Not implemented"
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
namespace misc {
namespace ranges = boost::range;
namespace views = boost::adaptors;
}
#else
#error
#endif