8namespace Stroika::Foundation::Containers::STL {
10 template <
typename ITERABLE_OF_T,
typename T, Common::IPotentiallyComparer<T> EQUALS_COMPARER>
11 bool equal (
const ITERABLE_OF_T& lhs,
const ITERABLE_OF_T& rhs, EQUALS_COMPARER&& equalsComparer)
13 return lhs.size () == rhs.size () and
equal (lhs.begin (), lhs.end (), rhs.begin (), equalsComparer);
21 template <
typename CREATE_CONTAINER_TYPE,
typename FROM_CONTAINER_TYPE>
22 inline CREATE_CONTAINER_TYPE Make (
const FROM_CONTAINER_TYPE& rhs)
24 return CREATE_CONTAINER_TYPE (rhs.begin (), rhs.end ());
32 template <
typename TARGET_CONTAINER>
33 inline void Append (TARGET_CONTAINER* v)
37 template <
typename TARGET_CONTAINER,
typename SRC_CONTAINER>
38 inline void Append (TARGET_CONTAINER* v,
const SRC_CONTAINER& v2)
41 size_t c = max (v->capacity (), v->size () + v2.size ());
43 v->insert (v->end (), v2.begin (), v2.end ());
45 template <
typename TARGET_CONTAINER,
typename SRC_CONTAINER,
typename... Args>
46 inline void Append (TARGET_CONTAINER* v,
const SRC_CONTAINER& v2, Args... args)
58 template <
typename TARGET_CONTAINER,
typename SRC_CONTAINER,
typename... Args>
59 TARGET_CONTAINER
Concat (
const SRC_CONTAINER& v2, Args... args)
62 Append (&tmp, v2, args...);
71 template <
typename SRC_CONTAINER,
typename... Args>
72 inline vector<typename SRC_CONTAINER::value_type>
Concatenate (
const SRC_CONTAINER& v2, Args... args)
74 return Concat<vector<typename SRC_CONTAINER::value_type>> (v2, args...);
85 for (
typename set<T>::const_iterator i = s1.begin (); i != s1.end (); ++i) {
86 if (s2.find (*i) != s2.end ()) {
99 vector<T> Intersection (
const vector<T>& s1,
const vector<T>& s2)
102 result.reserve (min (s1.size (), s2.size ()));
103 for (
typename vector<T>::const_iterator i = s1.begin (); i != s1.end (); ++i) {
104 if (find (s2.begin (), s2.end (), *i) != s2.end ()) {
105 result.push_back (*i);
110 template <
typename T>
114 for (
typename set<T>::const_iterator i = s1.begin (); i != s1.end (); ++i) {
115 if (s2.find (*i) != s2.end ()) {
121 template <
typename T>
122 void Intersection (set<T>* s1,
const set<T>& s2)
126 if (not s1->empty () and not s2.empty ()) {
127 *s1 = Intersection (*s1, s2);
136 template <
typename T,
typename FROMCONTAINER>
137 void Union (set<T>* s1,
const FROMCONTAINER& s2)
139 for (
const auto& i : s2) {
140 if (s1->find (i) == s1->end ()) {
145 template <
typename T,
typename FROMCONTAINER>
146 set<T> Union (
const set<T>& s1,
const FROMCONTAINER& s2)
158 template <
typename T,
typename FROMCONTAINER>
159 void Difference (set<T>* s1,
const FROMCONTAINER& s2)
162 for (
const auto& i : s2) {
163 if (s1->find (i) != s1->end ()) {
168 template <
typename T,
typename FROMCONTAINER>
169 set<T> Difference (
const set<T>& s1,
const FROMCONTAINER& s2)
172 Difference (&result, s2);
#define RequireNotNull(p)
set< T > Intersection(const set< T > &s1, const set< T > &s2)
bool Intersects(const set< T > &s1, const set< T > &s2)
void Append(TARGET_CONTAINER *v)
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.