4#ifndef _Stroika_Foundation_Traversal_Iterable_h_
5#define _Stroika_Foundation_Traversal_Iterable_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
16#include "Stroika/Foundation/Common/Common.h"
18#include "Stroika/Foundation/Common/Concepts.h"
22#include "Stroika/Foundation/Execution/Common.h"
68namespace Stroika::Foundation::Traversal {
71 using Common::IEqualsComparer;
72 using Common::IThreeWayComparer;
81 template <
typename ITERABLE,
template <
typename>
typename ITEM_PREDICATE =
Common::True>
82 concept IIterable = ranges::range<ITERABLE> and ITEM_PREDICATE<ranges::range_value_t<ITERABLE>>::value;
95 template <
typename ITERABLE,
typename OF_T>
107 template <
typename ITERABLE,
typename OF_T>
233 template <
typename T>
239#if !qCompilerAndStdLib_constructible_Buggy
291#if !qCompilerAndStdLib_constructible_Buggy
318 explicit Iterable (
const shared_ptr<_IRep>& rep)
noexcept;
319 explicit Iterable (shared_ptr<_IRep>&& rep)
noexcept;
334 nonvirtual
explicit operator bool ()
const;
419 nonvirtual
size_t size ()
const;
434 nonvirtual
bool empty ()
const;
451 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
472 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
474 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
485 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
487 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
505 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
508 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
510 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER>
511 [[
deprecated (
"Since Stroika v3.0d24 - useIterableSize is ignored; use the overload without it")]]
static bool
513 template <ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER>
514 [[
deprecated (
"Since Stroika v3.0d24 - useIterableSize is ignored; use the overload without it")]] nonvirtual
bool
518 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IEqualsComparer<T>) T_EQUALS_COMPARER = equal_to<T>>
519 struct SequentialEqualsComparer;
522 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) T_THREEWAY_COMPARER = compare_three_way>
523 struct SequentialThreeWayComparer;
735 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
737 template <predicate<T> THAT_FUNCTION>
739 template <predicate<T> THAT_FUNCTION>
741 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
743 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
761 template <IIterableOfFrom<T> CONTAINER_OF_T,
typename... CONTAINER_OF_T_CONSTRUCTOR_ARGS>
823#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
824 template <
typename RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
826 template <
typename RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
829 template <derived_from<Iterable<T>> RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
831 template <derived_from<Iterable<T>> RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
850 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
852 template <
typename RESULT, Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<RESULT>>
926 template <ranges::range RESULT_CONTAINER = Iterable<T>, invocable<T> ELEMENT_MAPPER>
930 template <ranges::range RESULT_CONTAINER = Iterable<T>, invocable<T> ELEMENT_MAPPER>
983 template <
typename REDUCED_TYPE = T>
990 template <
typename REDUCED_TYPE = T>
1006 template <same_as<Characters::String> RESULT_T = Characters::String>
1012 return Characters::UnoverloadedToString<T>;
1060#if qCompilerAndStdLib_template_SubstDefaultTemplateParamVariableTemplate_Buggy
1061 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<RESULT_T>),
1062 invocable<RESULT_T, RESULT_T,
bool> COMBINER = decltype (Characters::kDefaultStringCombiner)>
1068 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<>),
1069 invocable<RESULT_T, RESULT_T,
bool> COMBINER = decltype (Characters::kDefaultStringCombiner)>
1078 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT>
1185 template <Common::IPotentiallyComparer<T> COMPARER>
1187 template <Common::IPotentiallyComparer<T> COMPARER>
1254 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1256 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1266 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1296 template <invocable<T> F>
1299 template <
typename RESULT_T = T>
1317 template <invocable<T> F>
1337 template <invocable<T> F>
1340 template <
typename RESULT_T = T>
1357 template <invocable<T> F>
1403 template <
typename RESULT_TYPE = T>
1430 template <
typename RESULT_TYPE = T>
1450 template <
typename RESULT_TYPE = T>
1457 template <
typename RESULT_TYPE = T>
1477 template <
typename RESULT_TYPE = T>
1484 template <
typename RESULT_TYPE = T>
1500 template <constructible_from<T> RESULT_TYPE = T, Common::IPotentiallyComparer<RESULT_TYPE> INORDER_COMPARE_FUNCTION = less<RESULT_TYPE>>
1507 template <constructible_from<T> RESULT_TYPE = T>
1537 nonvirtual
bool Any ()
const;
1551 nonvirtual
size_t Count ()
const;
1558 nonvirtual
size_t length ()
const;
1570 static shared_ptr<_IRep> Clone_ (
const _IRep& rep);
1573 template <
typename CONTAINER_OF_T>
1585 template <
typename REP_SUB_TYPE = _IRep>
1586 class _SafeReadRepAccessor;
1589 template <
typename REP_SUB_TYPE = _IRep>
1590 class _SafeReadWriteRepAccessor;
1602 template <
typename SHARED_T>
1609 template <
typename SHARED_T>
1610 using enable_shared_from_this_PtrImplementationTemplate [[
deprecated (
"Since Stroika v3.0d1")]] = std::enable_shared_from_this<SHARED_T>;
1613 using _IterableRepSharedPtr [[
deprecated (
"Since Stroika v3.0d1 use shared_ptr<_IRep> directly")]] = shared_ptr<_IRep>;
1614 using _IteratorRepSharedPtr [[
deprecated (
"Since Stroika v3.0d1 use unique_ptr<typename Iterator<T>::IRep> directly")]] =
1636 template <
typename T>
1637 template <
typename REP_SUB_TYPE>
1650 nonvirtual
const REP_SUB_TYPE& _ConstGetRep ()
const noexcept;
1659#if qStroika_Foundation_Debug_AssertionsChecked
1676 template <
typename T>
1677 template <
typename REP_SUB_TYPE>
1697#if qStroika_Foundation_Debug_AssertionsChecked
1725 template <
typename T>
1731 virtual ~_IRep () =
default;
1736 virtual shared_ptr<_IRep> Clone ()
const = 0;
1751 virtual size_t size ()
const;
1757 virtual bool empty ()
const;
1870 template <
typename T>
1871 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IEqualsComparer<T>) T_EQUALS_COMPARER>
1886 template <
typename T>
1887 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) T_THREEWAY_COMPARER>
1894#if !qCompilerAndStdLib_constructible_Buggy
1898 static_assert (copyable<Iterable<int>>);
1908#include "Iterable.inl"
#define Stroika_ATTRIBUTE_NO_UNIQUE_ADDRESS_VCFORCE
[[msvc::no_unique_address]] isn't always broken in MSVC. Annotate with this on things where its not b...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
NOT a real mutex - just a debugging infrastructure support tool so in debug builds can be assured thr...
unique_lock< AssertExternallySynchronizedChecker > WriteContext
Instantiate AssertExternallySynchronizedChecker::WriteContext to designate an area of code where prot...
shared_lock< const AssertExternallySynchronizedChecker > ReadContext
Instantiate AssertExternallySynchronizedChecker::ReadContext to designate an area of code where prote...
SharedByValue is a utility class to implement Copy-On-Write (aka COW) - sort of halfway between uniqu...
Implementation detail for iterator implementors.
virtual Iterator< value_type > MakeIterator() const =0
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
nonvirtual RESULT_T Join(const CONVERT_TO_RESULT &convertToResult=kDefaultToStringConverter<>, const COMBINER &combiner=Characters::kDefaultStringCombiner) const
ape the JavaScript/python 'join' function - take the parts of 'this' iterable and combine them into a...
nonvirtual RESULT_TYPE MaxValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
nonvirtual Iterable< T > Slice(size_t from, size_t to) const
static bool SetEquals(const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{})
nonvirtual bool Any() const
Any() same as not empty (); Any (includeIfTrue) returns true iff includeIfTrue returns true on any va...
_SharedByValueRepType _fRep
nonvirtual optional< T > Max() const
nonvirtual RESULT_TYPE MedianValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
nonvirtual optional< RESULT_TYPE > Mean() const
nonvirtual Iterator< T > Find(THAT_FUNCTION &&that) const
Run the argument bool-returning function (or lambda) on the elements of the container,...
nonvirtual size_t length() const
STL-ish alias for size() - really in STL only used in string, I think, but still makes sense as an al...
nonvirtual CONTAINER_OF_T As(CONTAINER_OF_T_CONSTRUCTOR_ARGS... args) const
nonvirtual Iterable< T > Distinct(EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) const
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
functional API which iterates over all members of an Iterable, applies a map function to each element...
nonvirtual size_t Count() const
with no args, same as size, with function filter arg, returns number of items that pass.
nonvirtual RESULT_T Join(const CONVERT_TO_RESULT &convertToResult, const RESULT_T &separator, const optional< RESULT_T > &finalSeparator={}) const
Like Join (separator, finalSeparator), but convertToResult converts each element.
nonvirtual bool IsOrderedBy(INORDER_COMPARER_TYPE &&inorderComparer=INORDER_COMPARER_TYPE{}) const
nonvirtual Iterable< T > Repeat(size_t count) const
nonvirtual optional< T > First() const
return first element in iterable, or if 'that' specified, first where 'that' is true,...
T value_type
value_type is an alias for the type iterated over - like vector<T>::value_type
nonvirtual RESULT_TYPE MinValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
nonvirtual bool All(const function< bool(ArgByValueType< T >)> &testEachElt) const
return true iff argument predicate returns true for each element of the iterable
nonvirtual bool Contains(ArgByValueType< T > element, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) const
nonvirtual optional< T > Min() const
nonvirtual T NthValue(ptrdiff_t n, ArgByValueType< T > defaultValue={}) const
Find the Nth element of the Iterable<>, but allow for n to be out of range, and just return argument ...
nonvirtual size_t size() const
Returns the number of items contained.
Iterable(const shared_ptr< _IRep > &rep) noexcept
Iterable's are typically constructed as concrete subtype objects, whose CTOR passed in a shared copya...
nonvirtual RESULT_CONTAINER Where(INCLUDE_PREDICATE &&includeIfTrue) const
produce a subset of this iterable where argument function returns true
nonvirtual void Apply(const function< void(ArgByValueType< T > item)> &doToElement) const
Run the argument function (or lambda) on each element of the container.
nonvirtual T Nth(ptrdiff_t n) const
Find the Nth element of the Iterable<>
nonvirtual Iterable< T > Take(size_t nItems) const
nonvirtual RESULT_TYPE MeanValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
nonvirtual optional< RESULT_TYPE > Median(const INORDER_COMPARE_FUNCTION &compare={}) const
nonvirtual Iterable< T > Skip(size_t nItems) const
nonvirtual RESULT_TYPE SumValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
static const function< RESULT_T(T)> kDefaultToStringConverter
nonvirtual optional< REDUCED_TYPE > Reduce(const function< REDUCED_TYPE(ArgByValueType< T >, ArgByValueType< T >)> &op) const
Walk the entire list of items, and use the argument 'op' to combine (reduce) items to a resulting sin...
nonvirtual Iterator< T > begin() const
Support for ranged for, and STL syntax in general.
nonvirtual optional< T > Top() const
return the top/largest value (or the top N values) from this Iterable<T>
Iterable(const Iterable &) noexcept=default
Iterable are safely copyable (by value). Since Iterable uses COW, this just copies the underlying poi...
nonvirtual optional< RESULT_TYPE > Sum() const
nonvirtual Memory::SharedByValueSupport::SharingState _GetSharingState() const
static bool SequentialEquals(const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{})
nonvirtual bool empty() const
Returns true iff size() == 0.
nonvirtual T LastValue(ArgByValueType< T > defaultValue={}) const
static bool MultiSetEquals(const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{})
nonvirtual optional< T > Last() const
return last element in iterable, or if 'that' specified, last where 'that' is true,...
nonvirtual T FirstValue(ArgByValueType< T > defaultValue={}) const
return first element in iterable provided default
Iterable(Iterable &&) noexcept=default
Iterable are safely moveable.
static constexpr default_sentinel_t end() noexcept
Support for ranged for, and STL syntax in general.
nonvirtual REDUCED_TYPE ReduceValue(const function< REDUCED_TYPE(ArgByValueType< T >, ArgByValueType< T >)> &op, ArgByValueType< REDUCED_TYPE > defaultValue={}) const
nonvirtual Iterable< T > OrderBy(INORDER_COMPARER_TYPE &&inorderComparer=INORDER_COMPARER_TYPE{}) const
nonvirtual Iterator< T > MakeIterator() const
Create an iterator object which can be used to traverse the 'Iterable'.
An Iterator<T> is a copyable object which allows traversing the contents of some container.
String UnoverloadedToString(const T &t)
same as ToString()/1 - but without the potentially confusing multi-arg overloads (confused some templ...
const function< String(String, String, bool)> kDefaultStringCombiner
conditional_t<(sizeof(CHECK_T)<=2 *sizeof(void *)) and is_trivially_copyable_v< CHECK_T >, CHECK_T, const CHECK_T & > ArgByValueType
This is an alias for 'T' - but how we want to pass it on stack as formal parameter.
SequencePolicy
equivalent which of 4 types being used std::execution::sequenced_policy, parallel_policy,...
function object whose action is to map its argument, back to the same value it started with (identity...