Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ArchtypeClasses.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_Test_ArchtypeClasses_h_
5#define _Stroika_Frameworks_Test_ArchtypeClasses_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/Common/Common.h"
11
12/**
13 * This module needs a lot of work. Need a set of basic archetype classes for things that are not copyable, copyable, default constructible etc
14 * to use in regression test (especially container) test cases...
15 */
17
21
22 /**
23 * \brief IINTeroperable = constructible, and convertible to size_t int as well; for simple use in regression tests
24 */
25 template <typename T>
26 concept IINTeroperable = requires (T t) {
27 { static_cast<size_t> (T{1u}) } -> convertible_to<size_t>;
28 { T{1u} + T{1u} } -> convertible_to<T>;
29 };
30
31 /**
32 * \note Until Stroika v3.0d10 - this was called 'NotCopyable'
33 */
45 static_assert (default_initializable<OnlyDefaultConstructibleAndMoveable>);
46 static_assert (not copyable<OnlyDefaultConstructibleAndMoveable>);
47 static_assert (move_constructible<OnlyDefaultConstructibleAndMoveable>);
48 static_assert (not equality_comparable<OnlyDefaultConstructibleAndMoveable>);
49 static_assert (not totally_ordered<OnlyDefaultConstructibleAndMoveable>);
50 static_assert (not semiregular<OnlyDefaultConstructibleAndMoveable>);
51 static_assert (not regular<OnlyDefaultConstructibleAndMoveable>);
52
53 using NotCopyable [[deprecated ("Since Stroika v3.0d10 use OnlyDefaultConstructibleAndMoveable")]] = OnlyDefaultConstructibleAndMoveable;
54
55 /**
56 * Object NOT default constructible, is copyable (and assignable); supports operator+ and operator==, and operator<, operator <=>, etc
57 *
58 * \note before Stroika v3.0d10 this was called 'SimpleClass'
59 */
61 public:
62 OnlyCopyableMoveableAndTotallyOrdered () noexcept = delete;
67
70
71 [[deprecated ("Since Stroika v3.0d10 use static_cast<size_t>")]] size_t GetValue () const
72 {
73 return fValue_;
74 }
75 static size_t GetTotalLiveCount ();
76
78 explicit operator size_t () const;
79
80 bool operator== (const OnlyCopyableMoveableAndTotallyOrdered& rhs) const;
81 strong_ordering operator<=> (const OnlyCopyableMoveableAndTotallyOrdered& rhs) const;
82
83 private:
84 size_t fValue_;
85 int fConstructed_;
86 static inline size_t sTotalLiveObjects_{0};
87 };
88 static_assert (not default_initializable<OnlyCopyableMoveableAndTotallyOrdered>);
89 static_assert (copyable<OnlyCopyableMoveableAndTotallyOrdered>);
90 static_assert (move_constructible<OnlyCopyableMoveableAndTotallyOrdered>);
91 static_assert (equality_comparable<OnlyCopyableMoveableAndTotallyOrdered>);
92 static_assert (totally_ordered<OnlyCopyableMoveableAndTotallyOrdered>); // @todo allow this to be totally ordered...
93 static_assert (not semiregular<OnlyCopyableMoveableAndTotallyOrdered>);
94 static_assert (not regular<OnlyCopyableMoveableAndTotallyOrdered>);
96
97 using SimpleClass [[deprecated ("Since Stroika v3.0d10 use OnlyCopyableMoveableAndTotallyOrdered")]] = OnlyCopyableMoveableAndTotallyOrdered;
98
99 /**
100 * Object NOT default constructible, is copyable, assignable; supports operator+, but NO COMPARISON operators
101 * \note before Stroika v3.0d10 this was called 'SimpleClassWithoutComparisonOperators'
102 */
104 public:
105 OnlyCopyableMoveable () noexcept = delete;
108 OnlyCopyableMoveable (size_t v);
110
111 OnlyCopyableMoveable& operator= (OnlyCopyableMoveable&& rhs) = default;
112 OnlyCopyableMoveable& operator= (const OnlyCopyableMoveable&) = default;
113
114 [[deprecated ("Since Stroika v3.0d10 use static_cast<size_t>")]] size_t GetValue () const
115 {
116 return fValue_;
117 }
118 static size_t GetTotalLiveCount ();
119
120 explicit operator size_t () const;
121 OnlyCopyableMoveable operator+ (const OnlyCopyableMoveable& rhs) const;
122
123 private:
124 size_t fValue_;
125 int fConstructed_;
126 static inline size_t sTotalLiveObjects_{0};
127 };
128 static_assert (not default_initializable<OnlyCopyableMoveable>);
129 static_assert (copyable<OnlyCopyableMoveable>);
130 static_assert (move_constructible<OnlyCopyableMoveable>);
131 static_assert (not equality_comparable<OnlyCopyableMoveable>);
132 static_assert (not totally_ordered<OnlyCopyableMoveable>); // @todo allow this to be totally ordered...
133 static_assert (not semiregular<OnlyCopyableMoveable>);
134 static_assert (not regular<OnlyCopyableMoveable>);
136
137 using SimpleClassWithoutComparisonOperators [[deprecated ("Since Stroika v3.0d10 use OnlyCopyableMoveable")]] = OnlyCopyableMoveable;
138
139 /**
140 * \brief alias for 'regular' type (copyable, default constructible, equality_comparable, etc)
141 * @todo maybe do explicit class cuz Regular should NOT be totally_ordered, but int is...
142 */
143 using Regular = size_t;
144 static_assert (regular<Regular>);
145 static_assert (IINTeroperable<Regular>);
146
147 /**
148 * For types that don't have operator== bulletin, this saves a bit of typing producing a generic comparer (using IINTeroperable)
149 */
150 template <IINTeroperable T>
151 struct AsIntsEqualsComparer : ComparisonRelationDeclarationBase<ComparisonRelationType::eEquals> {
152 bool operator() (T v1, T v2) const
153 {
154 return static_cast<size_t> (v1) == static_cast<size_t> (v2);
155 }
156 };
157
158 /**
159 * For types that don't have operator< bulletin, this saves a bit of typing producing a generic comparer (using IINTeroperable)
160 */
161 template <IINTeroperable T>
162 struct AsIntsLessComparer : ComparisonRelationDeclarationBase<ComparisonRelationType::eStrictInOrder> {
163 bool operator() (T v1, T v2) const
164 {
165 return static_cast<size_t> (v1) < static_cast<size_t> (v2);
166 }
167 };
168
169 /**
170 * For types that don't have operator< bulletin, this saves a bit of typing producing a generic comparer (using IINTeroperable)
171 */
172 template <IINTeroperable T>
173 struct AsIntsThreeWayComparer : ComparisonRelationDeclarationBase<ComparisonRelationType::eThreeWayCompare> {
174 strong_ordering operator() (T v1, T v2) const
175 {
176 return static_cast<size_t> (v1) <=> static_cast<size_t> (v2);
177 }
178 };
179
180}
181#endif /* _Stroika_Frameworks_Test_ArchtypeClasses_h_ */
IINTeroperable = constructible, and convertible to size_t int as well; for simple use in regression t...
size_t Regular
alias for 'regular' type (copyable, default constructible, equality_comparable, etc)