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>
114#if qCompilerAndStdLib_lambdas_in_unevaluatedContext_warning_Buggy
115 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wsubobject-linkage\"")
237 template <
typename T>
243#if !qCompilerAndStdLib_constructible_Buggy
295#if !qCompilerAndStdLib_constructible_Buggy
322 explicit Iterable (
const shared_ptr<_IRep>& rep)
noexcept;
323 explicit Iterable (shared_ptr<_IRep>&& rep)
noexcept;
338 nonvirtual
explicit operator bool ()
const;
423 nonvirtual
size_t size ()
const;
438 nonvirtual
bool empty ()
const;
455 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
476 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
478 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
489 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
491 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
509 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
512 template <ranges::range RHS_CONTAINER_TYPE = initializer_list<T>, IEqualsComparer<T> EQUALS_COMPARER = equal_to<T>>
514 template <ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER>
515 [[
deprecated (
"Since Stroika v3.0d24 - useIterableSize is ignored; use the overload without it")]]
static bool
517 template <ranges::range RHS_CONTAINER_TYPE, IEqualsComparer<T> EQUALS_COMPARER>
518 [[
deprecated (
"Since Stroika v3.0d24 - useIterableSize is ignored; use the overload without it")]] nonvirtual
bool
522 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IEqualsComparer<T>) T_EQUALS_COMPARER = equal_to<T>>
523 struct SequentialEqualsComparer;
526 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) T_THREEWAY_COMPARER = compare_three_way>
527 struct SequentialThreeWayComparer;
739 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
741 template <predicate<T> THAT_FUNCTION>
743 template <predicate<T> THAT_FUNCTION>
745 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
747 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
765 template <IIterableOfFrom<T> CONTAINER_OF_T,
typename... CONTAINER_OF_T_CONSTRUCTOR_ARGS>
827#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
828 template <
typename RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
830 template <
typename RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
833 template <derived_from<Iterable<T>> RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
835 template <derived_from<Iterable<T>> RESULT_CONTAINER = Iterable<T>, predicate<T> INCLUDE_PREDICATE>
854 template <Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
856 template <
typename RESULT, Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<RESULT>>
930 template <ranges::range RESULT_CONTAINER = Iterable<T>, invocable<T> ELEMENT_MAPPER>
934 template <ranges::range RESULT_CONTAINER = Iterable<T>, invocable<T> ELEMENT_MAPPER>
987 template <
typename REDUCED_TYPE = T>
994 template <
typename REDUCED_TYPE = T>
1010 template <same_as<Characters::String> RESULT_T = Characters::String>
1016 return Characters::UnoverloadedToString<T>;
1064#if qCompilerAndStdLib_template_SubstDefaultTemplateParamVariableTemplate_Buggy
1065 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<RESULT_T>),
1066 invocable<RESULT_T, RESULT_T,
bool> COMBINER = decltype (Characters::kDefaultStringCombiner)>
1072 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<>),
1073 invocable<RESULT_T, RESULT_T,
bool> COMBINER = decltype (Characters::kDefaultStringCombiner)>
1079#if qCompilerAndStdLib_template_optionalDeclareIncompleteType_Buggy
1082 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT>
1085 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT>
1090 template <
typename RESULT_T = Characters::String, invocable<T> CONVERT_TO_RESULT>
1198 template <Common::IPotentiallyComparer<T> COMPARER>
1200 template <Common::IPotentiallyComparer<T> COMPARER>
1267 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1269 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1279 template <Common::IPotentiallyComparer<T> INORDER_COMPARER_TYPE = less<T>>
1309 template <invocable<T> F>
1312 template <
typename RESULT_T = T>
1330 template <invocable<T> F>
1350 template <invocable<T> F>
1353 template <
typename RESULT_T = T>
1370 template <invocable<T> F>
1416 template <
typename RESULT_TYPE = T>
1443 template <
typename RESULT_TYPE = T>
1463 template <
typename RESULT_TYPE = T>
1470 template <
typename RESULT_TYPE = T>
1490 template <
typename RESULT_TYPE = T>
1497 template <
typename RESULT_TYPE = T>
1513 template <constructible_from<T> RESULT_TYPE = T, Common::IPotentiallyComparer<RESULT_TYPE> INORDER_COMPARE_FUNCTION = less<RESULT_TYPE>>
1520 template <constructible_from<T> RESULT_TYPE = T>
1550 nonvirtual
bool Any ()
const;
1564 nonvirtual
size_t Count ()
const;
1571 nonvirtual
size_t length ()
const;
1583 static shared_ptr<_IRep> Clone_ (
const _IRep& rep);
1586 template <
typename CONTAINER_OF_T>
1598 template <
typename REP_SUB_TYPE = _IRep>
1599 class _SafeReadRepAccessor;
1602 template <
typename REP_SUB_TYPE = _IRep>
1603 class _SafeReadWriteRepAccessor;
1615 template <
typename SHARED_T>
1622 template <
typename SHARED_T>
1623 using enable_shared_from_this_PtrImplementationTemplate [[
deprecated (
"Since Stroika v3.0d1")]] = std::enable_shared_from_this<SHARED_T>;
1626 using _IterableRepSharedPtr [[
deprecated (
"Since Stroika v3.0d1 use shared_ptr<_IRep> directly")]] = shared_ptr<_IRep>;
1627 using _IteratorRepSharedPtr [[
deprecated (
"Since Stroika v3.0d1 use unique_ptr<typename Iterator<T>::IRep> directly")]] =
1631#if qCompilerAndStdLib_lambdas_in_unevaluatedContext_warning_Buggy
1632 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wsubobject-linkage\"")
1653 template <
typename T>
1654 template <
typename REP_SUB_TYPE>
1667 nonvirtual
const REP_SUB_TYPE& _ConstGetRep ()
const noexcept;
1676#if qStroika_Foundation_Debug_AssertionsChecked
1693 template <
typename T>
1694 template <
typename REP_SUB_TYPE>
1714#if qStroika_Foundation_Debug_AssertionsChecked
1742 template <
typename T>
1748 virtual ~_IRep () =
default;
1753 virtual shared_ptr<_IRep> Clone ()
const = 0;
1768 virtual size_t size ()
const;
1774 virtual bool empty ()
const;
1887 template <
typename T>
1888 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IEqualsComparer<T>) T_EQUALS_COMPARER>
1903 template <
typename T>
1904 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) T_THREEWAY_COMPARER>
1911#if !qCompilerAndStdLib_constructible_Buggy
1915 static_assert (copyable<Iterable<int>>);
1925#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...
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 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...