Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Containers/STL/Utilities.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Containers_STL_Utilities_h_
5#define _Stroika_Foundation_Containers_STL_Utilities_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <set>
10#include <vector>
11
12#include "Stroika/Foundation/Common/Common.h"
14
15/**
16* \file
17*
18* \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
19*
20*/
21
22namespace Stroika::Foundation::Containers::STL {
23
24 /**
25 * \note similar to std::equal () - but takes iterables as arguments, not iterators
26 */
27 template <typename ITERABLE_OF_T, typename T = typename ITERABLE_OF_T::value_type, Common::IPotentiallyComparer<T> EQUALS_COMPARER = equal_to<T>>
28 bool equal (const ITERABLE_OF_T& lhs, const ITERABLE_OF_T& rhs, EQUALS_COMPARER&& equalsComparer = {});
29
30 /*
31 * STL container constructors take a begin/end combo, but no CONTAINER ctor (except for same as starting).
32 * So to convert from set<T> to vector<T> is a pain (if you have a function returning set<>). To do pretty
33 * easily with STL, you need a named temporary. Thats basically all this helper function does.
34 *
35 * So instead of:
36 * set<T> tmp = funCall_returning_set();
37 * vector<T> realAnswer = vector<T> (tmp.begin (), tmp.end ());
38 *
39 * You can write:
40 * vector<T> realAnswer = STL::Make<vector<T>> (funCall_returning_set());
41 */
42 template <typename CREATE_CONTAINER_TYPE, typename FROM_CONTAINER_TYPE>
43 [[deprecated ("Since Stroika v3.0d5 just use Traversal::Map<> or more directly use STL(ranges)")]] CREATE_CONTAINER_TYPE
44 Make (const FROM_CONTAINER_TYPE& rhs);
45
46 /**
47 * Though you can append to a vector<> with
48 * insert (this->begin (), arg.begin (), arg.end ())
49 * That's awkward if 'arg' is an unnamed value - say the result of a function. You must
50 * assign to a named temporary. This helper makes that unneeded.
51 */
52 template <typename TARGET_CONTAINER>
53 void Append (TARGET_CONTAINER* v);
54 template <typename TARGET_CONTAINER, typename SRC_CONTAINER>
55 void Append (TARGET_CONTAINER* v, const SRC_CONTAINER& v2);
56 template <typename TARGET_CONTAINER, typename SRC_CONTAINER, typename... Args>
57 void Append (TARGET_CONTAINER* v, const SRC_CONTAINER& v2, Args... args);
58
59 /**
60 * \brief construct a new STL container by concatenating the args together.
61 *
62 * \note Hard to believe this is so awkward in STL!
63 *
64 * @see Concatenate
65 */
66 template <typename TARGET_CONTAINER, typename SRC_CONTAINER, typename... Args>
67 TARGET_CONTAINER Concat (const SRC_CONTAINER& v2, Args... args);
68
69 /**
70 * \brief construct a new vector<T> by concatenating the args together. Alias for Concat<vector<typename SRC_CONTAINER::value_type>> ()
71 *
72 * @see Concat
73 */
74 template <typename SRC_CONTAINER, typename... Args>
75 vector<typename SRC_CONTAINER::value_type> Concatenate (const SRC_CONTAINER& v2, Args... args);
76
77 /**
78 * Returns true if the intersetion of s1 and s2 is non-empty
79 */
80 template <typename T>
81 bool Intersects (const set<T>& s1, const set<T>& s2);
82
83 /**
84 *@todo - redo with RHS as arbirrary container. Probably redo with stroika Set<>
85 // maybe osbolete cuz can alway use
86 // (Containers::Set<T> (s1) & s2).As<vector<T>> ()
87 */
88 template <typename T>
89 set<T> Intersection (const set<T>& s1, const set<T>& s2);
90 template <typename T>
91 void Intersection (set<T>* s1, const set<T>& s2);
92 template <typename T>
93 vector<T> Intersection (const vector<T>& s1, const vector<T>& s2);
94
95 /**
96 */
97 template <typename T, typename FROMCONTAINER>
98 void Union (set<T>* s1, const FROMCONTAINER& s2);
99 template <typename T, typename FROMCONTAINER>
100 set<T> Union (const set<T>& s1, const FROMCONTAINER& s2);
101
102 /**
103 */
104 template <typename T, typename FROMCONTAINER>
105 void Difference (set<T>* s1, const FROMCONTAINER& s2);
106 template <typename T, typename FROMCONTAINER>
107 set<T> Difference (const set<T>& s1, const FROMCONTAINER& s2);
108
109}
110
111/*
112 ********************************************************************************
113 ***************************** Implementation Details ***************************
114 ********************************************************************************
115 */
116#include "Utilities.inl"
117
118#endif /*_Stroika_Foundation_Containers_STL_Utilities_h_*/
set< T > Intersection(const set< T > &s1, const set< T > &s2)
bool Intersects(const set< T > &s1, const set< T > &s2)
bool equal(const ITERABLE_OF_T &lhs, const ITERABLE_OF_T &rhs, EQUALS_COMPARER &&equalsComparer={})
vector< typename SRC_CONTAINER::value_type > Concatenate(const SRC_CONTAINER &v2, Args... args)
construct a new vector<T> by concatenating the args together. Alias for Concat<vector<typename SRC_CO...
TARGET_CONTAINER Concat(const SRC_CONTAINER &v2, Args... args)
construct a new STL container by concatenating the args together.