| 1 | #cxx . . $ `<file>/src/ranges.h`/ifndef RANGES_H |
| 2 | #define RANGES_Hcxx . . $ `src/ranges.h:2:9`! |
| 3 | |
| 4 | #include <algorithm> |
| 5 | |
| 6 | // This is a (partial) reimplementation of c++20 'std::ranges' stuff. |
| 7 | // In the future we can: |
| 8 | // * Replace '#include "ranges.h"' with '#include <ranges>'. |
| 9 | // * Replace 'ranges::xxx()' with 'std::ranges::xxx()'. |
| 10 | |
| 11 | // Reimplementation of c++20 std::identity. |
| 12 | struct identitycxx . . $ identity# { |
| 13 | template<typename T> |
| 14 | [[nodiscard]] constexpr T&& operatorcxx . . $ identity#`operator()`(587440dcb2b65d14).()(T&& t) const noexcept { |
| 15 | return stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<T>(t); |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | namespace rangescxx . . $ ranges/ { |
| 20 | |
| 21 | template<typename OutputRange, typename T> |
| 22 | void fillcxx . . $ ranges/fill(af49599c1c6f79df).(OutputRange&& range, const T& value) |
| 23 | { |
| 24 | stdcxx . . $ std/::fillcxx . . $ std/fill(4a9bfaed88eccda7).(stdcxx . . $ std/::begincxx . . $ std/begin(770b900966e3cb7).(range), stdcxx . . $ std/::endcxx . . $ std/end(770b900966e3cb7).(range), value); |
| 25 | } |
| 26 | |
| 27 | template<typename InputRange, typename T> |
| 28 | [[nodiscard]] auto findcxx . . $ ranges/find(9e10fecdb7a9cf11).(InputRange&& range, const T& value) |
| 29 | { |
| 30 | return stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(stdcxx . . $ std/::begincxx . . $ std/begin(770b900966e3cb7).(range), stdcxx . . $ std/::endcxx . . $ std/end(770b900966e3cb7).(range), value); |
| 31 | } |
| 32 | |
| 33 | template<typename InputRange, typename T, typename Proj> |
| 34 | [[nodiscard]] auto findcxx . . $ ranges/find(c6b1973d0ee1b721).(InputRange&& range, const T& value, Proj proj) |
| 35 | { |
| 36 | return find_if(stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<InputRange>(range), |
| 37 | [&](const auto& e) { return stdcxx . . $ std/::invokecxx . . $ std/invoke(2acc70346a3bed67).(proj, e) ==cxx . . $ `operator==`(8f8a8e6a6f1fc74b). value; }); |
| 38 | } |
| 39 | |
| 40 | template<typename InputRange, typename UnaryPredicate> |
| 41 | [[nodiscard]] auto find_ifcxx . . $ ranges/find_if(6e32342bc5f039e5).(InputRange&& range, UnaryPredicate pred) |
| 42 | { |
| 43 | return stdcxx . . $ std/::find_ifcxx . . $ std/find_if(f0a0a4f94ee5cb00).(stdcxx . . $ std/::begincxx . . $ std/begin(770b900966e3cb7).(range), stdcxx . . $ std/::endcxx . . $ std/end(770b900966e3cb7).(range), pred); |
| 44 | } |
| 45 | |
| 46 | template<typename ForwardRange, typename T, typename Compare = stdcxx . . $ std/::lesscxx . . $ std/less#<>, typename Proj = identitycxx . . $ identity#> |
| 47 | [[nodiscard]] auto lower_boundcxx . . $ ranges/lower_bound(c5b3648797bcaf4b).(ForwardRange&& range, const T& value, Compare comp = {}, Proj proj = {}) |
| 48 | { |
| 49 | auto comp2 = [&](const auto& x, const auto& y) { |
| 50 | return comp(stdcxx . . $ std/::invokecxx . . $ std/invoke(2acc70346a3bed67).(proj, x), y); |
| 51 | }; |
| 52 | return stdcxx . . $ std/::lower_boundcxx . . $ std/lower_bound(a92da12e15934614).(stdcxx . . $ std/::begincxx . . $ std/begin(770b900966e3cb7).(range), stdcxx . . $ std/::endcxx . . $ std/end(770b900966e3cb7).(range), value, comp2); |
| 53 | } |
| 54 | |
| 55 | template<typename ForwardRange, typename T, typename Compare = stdcxx . . $ std/::lesscxx . . $ std/less#<>, typename Proj = identitycxx . . $ identity#> |
| 56 | [[nodiscard]] auto upper_boundcxx . . $ ranges/upper_bound(c5b3648797bcaf4b).(ForwardRange&& range, const T& value, Compare comp = {}, Proj proj = {}) |
| 57 | { |
| 58 | auto comp2 = [&](const auto& x, const auto& y) { |
| 59 | return comp(x, stdcxx . . $ std/::invokecxx . . $ std/invoke(2acc70346a3bed67).(proj, y)); |
| 60 | }; |
| 61 | return stdcxx . . $ std/::upper_boundcxx . . $ std/upper_bound(a92da12e15934614).(stdcxx . . $ std/::begincxx . . $ std/begin(770b900966e3cb7).(range), stdcxx . . $ std/::endcxx . . $ std/end(770b900966e3cb7).(range), value, comp2); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | // Not part of standard c++ (but has been proposed for a future version) |
| 66 | // This is more convenient to use than find(), if you don't care where in the |
| 67 | // range the element is located. |
| 68 | template<typename ForwardRange, typename T> |
| 69 | [[nodiscard]] bool containscxx . . $ ranges/contains(262953c0449c695f).(ForwardRange&& range, const T& value) |
| 70 | { |
| 71 | return findcxx . . $ ranges/find(c6b1973d0ee1b721).(range, value) !=cxx . . $ `operator!=`(8f8a8e6a6f1fc74b). stdcxx . . $ std/::endcxx . . $ std/end(770b900966e3cb7).(range); |
| 72 | } |
| 73 | } // namespace ranges |
| 74 | |
| 75 | #endif |