130#if defined(ALEPH_NO_RANGES)
131#undef ALEPH_HAS_RANGES
132#define ALEPH_HAS_RANGES 0
139#if __has_include(<version>)
143#ifndef ALEPH_HAS_RANGES
144#if __cplusplus >= 202002L && __has_include(<ranges>) && \
145 defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 202106L
147#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 160000
148#define ALEPH_HAS_RANGES 0
150#define ALEPH_HAS_RANGES 1
153#define ALEPH_HAS_RANGES 0
168#ifdef __cpp_lib_ranges_stride
169#define ALEPH_HAS_STRIDE 1
171#define ALEPH_HAS_STRIDE 0
174#ifdef __cpp_lib_ranges_repeat
175#define ALEPH_HAS_REPEAT 1
177#define ALEPH_HAS_REPEAT 0
180#ifdef __cpp_lib_ranges_zip
181#define ALEPH_HAS_ZIP 1
183#define ALEPH_HAS_ZIP 0
186#ifdef __cpp_lib_ranges_enumerate
187#define ALEPH_HAS_ENUMERATE 1
189#define ALEPH_HAS_ENUMERATE 0
198#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000
199#define ALEPH_HAS_JOIN 0
201#define ALEPH_HAS_JOIN 1
204#include <type_traits>
226template <
typename Range,
typename Cmp>
230 std::ranges::sort(
r, std::move(
cmp));
234 std::sort(std::begin(
r), std::end(
r), std::move(
cmp));
242template <
typename Range>
246 std::ranges::sort(
r, std::ranges::less{});
250 std::sort(std::begin(
r), std::end(
r));
289concept AlephContainer =
requires(C c) {
290 typename C::Iterator;
291 typename C::Item_Type;
292 { c.begin() } -> std::input_or_output_iterator;
293 { c.end() } -> std::sentinel_for<
decltype(c.begin())>;
300concept AlephAppendable =
301 AlephContainer<C> &&
requires(C c,
typename C::Item_Type v) { c.append(v); };
307concept RangeLike = std::ranges::range<R>;
330template <AlephAppendable Container, RangeLike R>
334 for (
auto &&elem :
r)
335 result.append(
std::forward<decltype(elem)>(elem));
367template <
typename T =
int>
368[[nodiscard]]
constexpr auto lazy_range(
T start,
T end)
370 return std::views::iota(start, end);
379template <
typename T =
int>
380[[nodiscard]]
constexpr auto lazy_range(
T n)
382 return std::views::iota(
T{0}, n);
400template <
typename T =
int>
401[[nodiscard]]
constexpr auto lazy_iota(
T start =
T{0})
403 return std::views::iota(start);
415[[nodiscard]]
constexpr auto lazy_repeat(
const T &
value,
size_t n)
417 return std::views::repeat(
value) | std::views::take(n);
432template <RangeLike R,
typename Pred>
435 return std::ranges::all_of(std::forward<R>(
r), std::forward<Pred>(
pred));
443template <RangeLike R,
typename Pred>
446 return std::ranges::any_of(std::forward<R>(
r), std::forward<Pred>(
pred));
454template <RangeLike R,
typename Pred>
457 return std::ranges::none_of(std::forward<R>(
r), std::forward<Pred>(
pred));
465template <RangeLike R,
typename Pred>
466[[nodiscard]]
constexpr auto ranges_find_if(R &&
r, Pred &&
pred)
468 return std::ranges::find_if(std::forward<R>(
r), std::forward<Pred>(
pred));
474template <RangeLike R,
typename Pred>
477 return std::ranges::count_if(std::forward<R>(
r), std::forward<Pred>(
pred));
485template <RangeLike R,
typename Func>
486[[nodiscard]]
constexpr auto ranges_transform(R &&
r, Func &&func)
488 return std::forward<R>(
r) | std::views::transform(std::forward<Func>(func));
496template <RangeLike R,
typename Pred>
497[[nodiscard]]
constexpr auto ranges_filter(R &&
r, Pred &&
pred)
499 return std::forward<R>(
r) | std::views::filter(std::forward<Pred>(
pred));
505template <RangeLike R>
506[[nodiscard]]
constexpr auto ranges_take(R &&
r,
size_t n)
508 return std::forward<R>(
r) | std::views::take(n);
514template <RangeLike R>
515[[nodiscard]]
constexpr auto ranges_drop(R &&
r,
size_t n)
517 return std::forward<R>(
r) | std::views::drop(n);
525template <RangeLike R>
526 requires std::ranges::bidirectional_range<R>
527[[nodiscard]]
constexpr auto ranges_reverse(R &&
r)
529 return std::forward<R>(
r) | std::views::reverse;
536template <RangeLike R>
537[[nodiscard]]
constexpr auto ranges_flatten(R &&
r)
539 return std::forward<R>(
r) | std::views::join;
547template <RangeLike... Rs>
548[[nodiscard]]
constexpr auto ranges_zip(Rs &&...rs)
550 return std::views::zip(std::forward<Rs>(rs)...);
554#if ALEPH_HAS_ENUMERATE
558template <RangeLike R>
559[[nodiscard]]
constexpr auto ranges_enumerate(R &&
r)
561 return std::forward<R>(
r) | std::views::enumerate;
574template <RangeLike R,
typename T,
typename BinaryOp>
577#ifdef __cpp_lib_ranges_fold
578 if constexpr (
requires { std::ranges::fold_left(std::forward<R>(
r),
init,
579 std::forward<BinaryOp>(op)); })
580 return std::ranges::fold_left(std::forward<R>(
r),
init, std::forward<BinaryOp>(op));
585 for (
auto &&elem :
r)
594template <RangeLike R>
595[[nodiscard]]
constexpr auto ranges_sum(R &&
r)
597 using T = std::ranges::range_value_t<R>;
604template <RangeLike R>
605[[nodiscard]]
constexpr auto ranges_product(R &&
r)
607 using T = std::ranges::range_value_t<R>;
614template <RangeLike R>
615[[nodiscard]]
constexpr auto ranges_min(R &&
r)
617 return std::ranges::min_element(std::forward<R>(
r));
623template <RangeLike R>
624[[nodiscard]]
constexpr auto ranges_max(R &&
r)
626 return std::ranges::max_element(std::forward<R>(
r));
632template <RangeLike R,
typename Comp = std::less<>>
633constexpr void ranges_sort(R &&
r, Comp &&comp = Comp{})
635 std::ranges::sort(std::forward<R>(
r), std::forward<Comp>(comp));
651struct aleph_adaptor_tag
659concept AlephAdaptor = std::derived_from<std::remove_cvref_t<T>, aleph_adaptor_tag>;
670template <
typename R, AlephAdaptor Adaptor>
671 requires std::ranges::range<std::remove_cvref_t<R>>
672[[nodiscard]]
auto operator | (R &&
r,
const Adaptor &adaptor)
674 return adaptor(std::forward<R>(
r));
682template <
template <
typename>
class Container>
683struct to_aleph_adaptor : aleph_adaptor_tag
685 template <
typename R>
686 requires std::ranges::range<std::remove_cvref_t<R>>
687 [[nodiscard]]
auto operator () (R &&
r)
const
689 using T = std::ranges::range_value_t<std::remove_cvref_t<R>>;
691 for (
auto &&elem :
r)
692 result.append(
std::forward<decltype(elem)>(elem));
707inline constexpr to_aleph_adaptor<DynList> to_dynlist_v{};
712inline constexpr to_aleph_adaptor<DynArray> to_dynarray_v{};
717inline constexpr to_aleph_adaptor<DynDlist> to_dyndlist_v{};
722template <
template <
typename>
class Container>
723struct to_aleph_push_adaptor : aleph_adaptor_tag
725 template <
typename R>
726 requires std::ranges::range<std::remove_cvref_t<R>>
727 [[nodiscard]]
auto operator () (R &&
r)
const
729 using T = std::ranges::range_value_t<std::remove_cvref_t<R>>;
731 for (
auto &&elem :
r)
732 result.
push(
std::forward<decltype(elem)>(elem));
741inline constexpr to_aleph_push_adaptor<DynListStack> to_dynliststack_v{};
746inline constexpr to_aleph_push_adaptor<ArrayStack> to_arraystack_v{};
751template <
template <
typename>
class Container>
752struct to_aleph_put_adaptor : aleph_adaptor_tag
754 template <
typename R>
755 requires std::ranges::range<std::remove_cvref_t<R>>
756 [[nodiscard]]
auto operator () (R &&
r)
const
758 using T = std::ranges::range_value_t<std::remove_cvref_t<R>>;
760 for (
auto &&elem :
r)
761 result.put(
std::forward<decltype(elem)>(elem));
769inline constexpr to_aleph_put_adaptor<DynListQueue> to_dynlistqueue_v{};
774inline constexpr to_aleph_put_adaptor<ArrayQueue> to_arrayqueue_v{};
779inline constexpr to_aleph_adaptor<Random_Set> to_randomset_v{};
784template <
template <
typename,
typename...>
class Container,
typename... ExtraArgs>
785struct to_aleph_insert_adaptor : aleph_adaptor_tag
787 template <
typename R>
788 requires std::ranges::range<std::remove_cvref_t<R>>
789 [[nodiscard]]
auto operator () (R &&
r)
const
791 using T = std::ranges::range_value_t<std::remove_cvref_t<R>>;
793 for (
auto &&elem :
r)
794 result.
insert(
std::forward<decltype(elem)>(elem));
818template <
typename Container, RangeLike R>
822 for (
auto &&elem :
r)
824 if constexpr (
requires { result.append(elem); })
825 result.append(std::forward<
decltype(elem)>(elem));
826 else if constexpr (
requires { result.insert(elem); })
827 result.insert(std::forward<
decltype(elem)>(elem));
828 else if constexpr (
requires { result.push(elem); })
829 result.push(std::forward<
decltype(elem)>(elem));
832 "Container must have append(), insert(), or push() method");
848template <
typename Container>
849struct to_adaptor : aleph_adaptor_tag
851 template <
typename R>
852 requires std::ranges::range<std::remove_cvref_t<R>>
853 [[nodiscard]]
Container operator () (R &&
r)
const
855 return collect<Container>(std::forward<R>(
r));
872template <
typename Container>
873[[nodiscard]]
constexpr to_adaptor<Container> to()
890template <
typename Container,
typename Pred>
893 for (
auto it = c.get_it(); it.has_curr(); it.next_ne())
894 if (!
pred(it.get_curr()))
899template <
typename Container,
typename Pred>
902 for (
auto it = c.get_it(); it.has_curr(); it.next_ne())
903 if (
pred(it.get_curr()))
908template <
typename Container,
typename Pred>
920template <
typename Container,
typename T,
typename BinaryOp>
923 for (
auto &&elem : c)
931template <
typename Container,
typename Pred>
934 for (
const auto &elem : c)
943template <
typename Container,
typename Pred>
946 for (
const auto &elem : c)
955template <
typename Container,
typename Pred>
964template <
typename Container,
typename Pred>
968 for (
const auto &elem : c)
size_t size_t int32_t value
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_binary_ior > > operator|(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Freq_Node * pred
Predecessor node in level-order traversal.
bool fallback_all_of(const Container &c, Pred &&pred)
auto ranges_count_if(const Container &c, Pred &&pred)
Fallback count_if using range-based for loop.
bool fallback_any_of(const Container &c, Pred &&pred)
constexpr T ranges_fold_left(Container &&c, T init, BinaryOp &&op)
Fallback fold_left using range-based for loop.
bool ranges_none_of(const Container &c, Pred &&pred)
Fallback none_of using range-based for loop.
bool fallback_none_of(const Container &c, Pred &&pred)
bool ranges_any_of(const Container &c, Pred &&pred)
Fallback any_of using range-based for loop.
bool ranges_all_of(const Container &c, Pred &&pred)
Fallback all_of using range-based for loop.
Main namespace for Aleph-w library functions.
void sort_range(Range &r, Cmp cmp)
Sort a whole range in place, portably across the ranges divide.
std::decay_t< typename HeadC::Item_Type > T
static std::atomic< bool > init
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.