4#ifndef _Stroika_Foundation_Traversal_Iterable_h_
5#define _Stroika_Foundation_Traversal_Iterable_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
15#include "Stroika/Foundation/Common/Common.h"
17#include "Stroika/Foundation/Common/Concepts.h"
21#include "Stroika/Foundation/Execution/Common.h"
67namespace Stroika::Foundation::Traversal {
70 using Common::IEqualsComparer;
71 using Common::IThreeWayComparer;
80 template <
typename ITERABLE,
template <
typename>
typename ITEM_PREDICATE =
Common::True>
81 concept IIterable = ranges::range<ITERABLE> and ITEM_PREDICATE<ranges::range_value_t<ITERABLE>>::value;
94 template <
typename ITERABLE,
typename OF_T>
106 template <
typename ITERABLE,
typename OF_T>
113#if qCompilerAndStdLib_lambdas_in_unevaluatedContext_warning_Buggy
114 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wsubobject-linkage\"")
236 template <
typename T>
242#if !qCompilerAndStdLib_constructible_Buggy
294#if !qCompilerAndStdLib_constructible_Buggy
321 explicit Iterable (
const shared_ptr<_IRep>& rep)
noexcept;
322 explicit Iterable (shared_ptr<_IRep>&& rep)
noexcept;
337 nonvirtual
explicit operator bool ()
const;
377 nonvirtual
size_t size ()
const;
392 nonvirtual
bool empty ()
const;
409 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
430 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
432 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
444 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
446 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
461 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
464 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
469 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IEqualsComparer<T>) T_EQUALS_COMPARER = equal_to<T>>
470 struct SequentialEqualsComparer;
473 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) T_THREEWAY_COMPARER = compare_three_way>
474 struct SequentialThreeWayComparer;
557 Execution::SequencePolicy
seq = Execution::SequencePolicy::eDEFAULT)
const;
624 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER>
627 template <predicate<T> THAT_FUNCTION>
630 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER>
648 template <IIterableOfFrom<T> CONTAINER_OF_T,
typename... CONTAINER_OF_T_CONSTRUCTOR_ARGS>
710#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
711 template <
typename RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
713 template <
typename RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
716 template <derived_from<Iterable<T>> RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
718 template <derived_from<Iterable<T>> RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
737 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
739 template <
typename RESULT, Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<RESULT>>
813 template <ranges::range RESULT_CONTAINER = Iterable<T>, invocable<T> ELEMENT_MAPPER>
817 template <ranges::range RESULT_CONTAINER = Iterable<T>, invocable<T> ELEMENT_MAPPER>
861 template <
typename REDUCED_TYPE = T>
868 template <
typename REDUCED_TYPE = T>
884 template <same_as<Characters::String> RESULT_T = Characters::String>
890 return Characters::UnoverloadedToString<T>;
938#if qCompilerAndStdLib_template_SubstDefaultTemplateParamVariableTemplate_Buggy
939 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<RESULT_T>),
940 invocable<RESULT_T, RESULT_T,
bool> COMBINER = decltype (Characters::kDefaultStringCombiner)>
946 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<>),
947 invocable<RESULT_T, RESULT_T,
bool> COMBINER = decltype (Characters::kDefaultStringCombiner)>
953#if qCompilerAndStdLib_template_optionalDeclareIncompleteType_Buggy
956 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT>
959 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT>
964 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT>
1053 template <Common::IPotentiallyComparer<T> COMPARER>
1055 template <Common::IPotentiallyComparer<T> COMPARER>
1090 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1101 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1130 template <invocable<T> F>
1133 template <
typename RESULT_T = T>
1151 template <invocable<T> F>
1171 template <invocable<T> F>
1174 template <
typename RESULT_T = T>
1191 template <invocable<T> F>
1237 template <
typename RESULT_TYPE = T>
1264 template <
typename RESULT_TYPE = T>
1284 template <
typename RESULT_TYPE = T>
1291 template <
typename RESULT_TYPE = T>
1311 template <
typename RESULT_TYPE = T>
1318 template <
typename RESULT_TYPE = T>
1334 template <constructible_from<T> RESULT_TYPE = T, Common::IPotentiallyComparer<RESULT_TYPE> INORDER_COMPARE_FUNCTION = less<RESULT_TYPE>>
1341 template <constructible_from<T> RESULT_TYPE = T>
1371 nonvirtual
bool Any ()
const;
1385 nonvirtual
size_t Count ()
const;
1392 nonvirtual
size_t length ()
const;
1404 static shared_ptr<_IRep> Clone_ (
const _IRep& rep);
1407 template <
typename CONTAINER_OF_T>
1419 template <
typename REP_SUB_TYPE = _IRep>
1420 class _SafeReadRepAccessor;
1423 template <
typename REP_SUB_TYPE = _IRep>
1424 class _SafeReadWriteRepAccessor;
1436 template <
typename SHARED_T>
1443 template <
typename SHARED_T>
1444 using enable_shared_from_this_PtrImplementationTemplate [[
deprecated (
"Since Stroika v3.0d1")]] = std::enable_shared_from_this<SHARED_T>;
1447 using _IterableRepSharedPtr [[
deprecated (
"Since Stroika v3.0d1 use shared_ptr<_IRep> directly")]] = shared_ptr<_IRep>;
1448 using _IteratorRepSharedPtr [[
deprecated (
"Since Stroika v3.0d1 use unique_ptr<typename Iterator<T>::IRep> directly")]] =
1452#if qCompilerAndStdLib_lambdas_in_unevaluatedContext_warning_Buggy
1453 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wsubobject-linkage\"")
1474 template <
typename T>
1475 template <
typename REP_SUB_TYPE>
1488 nonvirtual
const REP_SUB_TYPE& _ConstGetRep ()
const noexcept;
1497#if qStroika_Foundation_Debug_AssertionsChecked
1514 template <
typename T>
1515 template <
typename REP_SUB_TYPE>
1535#if qStroika_Foundation_Debug_AssertionsChecked
1563 template <
typename T>
1569 virtual ~_IRep () =
default;
1574 virtual shared_ptr<_IRep> Clone ()
const = 0;
1589 virtual size_t size ()
const;
1595 virtual bool empty ()
const;
1642 template <
typename T>
1643 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IEqualsComparer<T>) T_EQUALS_COMPARER>
1648 bool fUseIterableSize;
1657 template <
typename T>
1658 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) T_THREEWAY_COMPARER>
1665#if !qCompilerAndStdLib_constructible_Buggy
1669 static_assert (copyable<Iterable<int>>);
1679#include "Iterable.inl"
#define qStroika_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...
shared_lock< const AssertExternallySynchronizedMutex > ReadContext
Instantiate AssertExternallySynchronizedMutex::ReadContext to designate an area of code where protect...
unique_lock< AssertExternallySynchronizedMutex > WriteContext
Instantiate AssertExternallySynchronizedMutex::WriteContext to designate an area of code where protec...
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 void Apply(const function< void(ArgByValueType< T > item)> &doToElement, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument function (or lambda) on each element of the container.
nonvirtual RESULT_TYPE MaxValue(ArgByValueType< RESULT_TYPE > defaultValue={}) const
nonvirtual Iterable< T > Slice(size_t from, size_t to) const
nonvirtual Iterator< T > Find(THAT_FUNCTION &&that, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument bool-returning function (or lambda) on each element of the container,...
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 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 Iterable< T > Top() const
return the top/largest (possibly just top N) values from this Iterable<T>
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 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 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 > OrderBy(INORDER_COMPARER_TYPE &&inorderComparer=INORDER_COMPARER_TYPE{}, Execution::SequencePolicy seq=Execution::SequencePolicy::ePar) 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.
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
nonvirtual bool empty() const
Returns true iff size() == 0.
nonvirtual T LastValue(ArgByValueType< T > defaultValue={}) const
static bool SequentialEquals(const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}, bool useIterableSize=false)
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 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,...
@ ePar
must synchronize shared data, can use mutex (or atomics), cuz each parallel execution in real thread
function object whose action is to map its argument, back to the same value it started with (identity...