Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Adder.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Containers_Adapters_Adder_h_
5#define _Stroika_Foundation_Containers_Adapters_Adder_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/Common/Common.h"
10
11/*
12 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
13 */
14
15namespace Stroika::Foundation::Containers::Adapters {
16
18
19 /**
20 * Concept to say if Adder is supported.
21 *
22 * Really just any container that supports (with a single argument of the value_type):
23 * o push_back
24 * o push_front
25 * o Add ()
26 * o insert
27 *
28 * \note Compatable with (not exhaustive list)
29 * o std::set
30 * o std::vector
31 * o std::map
32 * o Containers::Sequence
33 * o Containers::Collection
34 * o Containers::KeyedCollection
35 * o Containers::Mapping
36 * o Containers::Multiset
37 */
38 template <typename CONTAINER>
39 concept IAddableTo = requires (CONTAINER p) { p.push_back (declval<typename CONTAINER::value_type> ()); } or
40 requires (CONTAINER p) { p.push_front (declval<typename CONTAINER::value_type> ()); } or
41 requires (CONTAINER p) { p.Add (declval<typename CONTAINER::value_type> ()); } or
42 requires (CONTAINER p) { p.insert (declval<typename CONTAINER::value_type> ()); };
43
44 /**
45 * Concept that returns true if the given type of element ELT2ADD can be added to the argument container.
46 *
47 * This corresponds to if you can construct an Adder adapter on the template, and invoke .Add on it with the argument type.
48 */
49 template <typename ELT2ADD, typename CONTAINER>
50 concept IAddableCompatible = IAddableTo<CONTAINER> and convertible_to<ELT2ADD, typename CONTAINER::value_type>;
51
52 /**
53 * \brief utility for generic code that wishes to add something to a somewhat arbitrary container, where the ordering
54 * of the addition is undefined/doesn't matter (whatever makes sense by default for that container).
55 */
56 template <IAddableTo CONTAINER_TYPE>
57 struct Adder {
58 public:
59 /**
60 */
61 using value_type = typename CONTAINER_TYPE::value_type;
62
63 public:
64 /**
65 */
66 static void Add (CONTAINER_TYPE* container, Common::ArgByValueType<value_type> value);
67 };
68
69}
70
71/*
72 ********************************************************************************
73 ******************************* Implementation Details *************************
74 ********************************************************************************
75 */
76#include "Adder.inl"
77
78#endif /*_Stroika_Foundation_Containers_Adapters_Adder_h_ */
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.
Definition TypeHints.h:32
utility for generic code that wishes to add something to a somewhat arbitrary container,...
Definition Adder.h:57