Library: builder to add heterogeneous elements
...turns out that we must ensure to pass a plain "object" type to the standard allocator framework (no const, no references). Here, ''object in C++ terminology'' means a scalar or record type, but no functor, no references and no void,
This commit is contained in:
parent
1a76fb46f3
commit
601a555e6c
4 changed files with 73 additions and 28 deletions
|
|
@ -95,12 +95,13 @@ namespace mobject{
|
|||
namespace lib {
|
||||
namespace meta {
|
||||
|
||||
using std::remove_cv;
|
||||
using std::remove_cv_t;
|
||||
using std::remove_pointer;
|
||||
using std::remove_pointer_t;
|
||||
using std::remove_reference;
|
||||
using std::remove_reference_t;
|
||||
using std::conditional_t;
|
||||
using std::is_reference_v;
|
||||
using std::is_lvalue_reference_v;
|
||||
using std::is_rvalue_reference_v;
|
||||
using std::is_pointer;
|
||||
using std::is_base_of;
|
||||
using std::is_convertible;
|
||||
|
|
@ -248,7 +249,11 @@ namespace meta {
|
|||
template<typename X>
|
||||
struct Strip
|
||||
{
|
||||
using TypeUnconst = remove_cv_t<X>;
|
||||
using TypeUnconst = conditional_t<is_reference_v<X>
|
||||
, conditional_t<is_rvalue_reference_v<X>
|
||||
, remove_cv_t<remove_reference_t<X>> &&
|
||||
, remove_cv_t<remove_reference_t<X>> & >
|
||||
, remove_cv_t<X>>;
|
||||
using TypeReferred = remove_reference_t<TypeUnconst>;
|
||||
using TypePointee = remove_pointer_t<TypeReferred>;
|
||||
using TypePlain = remove_cv_t<TypePointee>;
|
||||
|
|
|
|||
|
|
@ -93,6 +93,9 @@ namespace lib {
|
|||
using std::is_trivially_destructible_v;
|
||||
using std::has_virtual_destructor_v;
|
||||
using std::is_trivially_copyable_v;
|
||||
using std::is_object_v;
|
||||
using std::is_volatile_v;
|
||||
using std::is_const_v;
|
||||
using std::is_same_v;
|
||||
using lib::meta::is_Subclass;
|
||||
|
||||
|
|
@ -290,6 +293,17 @@ namespace lib {
|
|||
return move(*this);
|
||||
}
|
||||
|
||||
template<typename VAL, typename...VALS>
|
||||
SeveralBuilder&&
|
||||
append (VAL&& val, VALS&& ...vals)
|
||||
{
|
||||
emplace<VAL> (forward<VAL> (val));
|
||||
if constexpr (0 < sizeof...(VALS))
|
||||
return append (forward<VALS> (vals)...);
|
||||
else
|
||||
return move(*this);
|
||||
}
|
||||
|
||||
template<class IT>
|
||||
SeveralBuilder&&
|
||||
appendAll (IT&& data)
|
||||
|
|
@ -321,7 +335,7 @@ namespace lib {
|
|||
SeveralBuilder&&
|
||||
emplace (ARGS&& ...args)
|
||||
{
|
||||
using Val = typename meta::RefTraits<TY>::Value;
|
||||
using Val = typename meta::Strip<TY>::TypeReferred;
|
||||
emplaceNewElm<Val> (forward<ARGS> (args)...);
|
||||
return move(*this);
|
||||
}
|
||||
|
|
@ -355,6 +369,8 @@ namespace lib {
|
|||
void
|
||||
emplaceNewElm (ARGS&& ...args)
|
||||
{
|
||||
static_assert (is_object_v<TY> and not (is_const_v<TY> or is_volatile_v<TY>));
|
||||
|
||||
// mark when target type is not trivially movable
|
||||
probeMoveCapability<TY>();
|
||||
|
||||
|
|
|
|||
|
|
@ -154,26 +154,15 @@ namespace test{
|
|||
CHECK ( isnil(builder));
|
||||
CHECK (not isnil(elms));
|
||||
CHECK (7 == elms.size());
|
||||
SHOW_EXPR(elms[0])
|
||||
SHOW_EXPR(elms[0].getVal())
|
||||
CHECK (elms[0].getVal() == (3+1)*3); // indeed a Num<3> with default-seed ≡ 3
|
||||
SHOW_EXPR(elms[0].calc(1))
|
||||
CHECK (elms[0].calc(1) == 3 + 1 + (3+3+3)); // indeed called the overridden calc() operation
|
||||
SHOW_EXPR(elms[1].getVal())
|
||||
CHECK (elms[1].getVal() == (2+1)*1); // indeed a Num<2> with seed ≡ 1
|
||||
SHOW_EXPR(elms[1].calc(1))
|
||||
CHECK (elms[1].calc(1) == 2 + 1 + (1+1)); // indeed the overridden calc() picking from the Array(1,1)
|
||||
SHOW_EXPR(elms[2].getVal())
|
||||
CHECK (isLimited (1, elms[2].getVal(), 100'000'000)); // indeed a Dummy with default random seed
|
||||
SHOW_EXPR(elms[3].getVal())
|
||||
CHECK (isLimited (1, elms[3].getVal(), 100'000'000)); // and this one too, since we filled in two instances
|
||||
SHOW_EXPR(elms[4].getVal())
|
||||
CHECK (elms[4].getVal() == 5); // followed by tree instances Dummy(5)
|
||||
SHOW_EXPR(elms[5].getVal())
|
||||
CHECK (elms[5].getVal() == 5);
|
||||
SHOW_EXPR(elms[6].getVal())
|
||||
CHECK (elms[6].getVal() == 5);
|
||||
SHOW_EXPR(elms[6].calc(1))
|
||||
CHECK (elms[6].calc(1) == 5+1); // indeed invoking the base implementation of calc()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83063,8 +83063,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node CREATED="1716936092764" ID="ID_618217173" MODIFIED="1716936100479" TEXT="Objekte einzeln verschieben"/>
|
||||
<node CREATED="1716936101233" ID="ID_1155209653" MODIFIED="1716936109052" TEXT="per std::memmove"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716914892972" ID="ID_1080699305" MODIFIED="1716914902543" TEXT="Platzieren neuer Daten">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1716914892972" ID="ID_1080699305" MODIFIED="1718147544739" TEXT="Platzieren neuer Daten">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node BACKGROUND_COLOR="#c8c0b6" COLOR="#435e98" CREATED="1718109947743" ID="ID_1627078678" MODIFIED="1718113032356" TEXT="Anforderungen">
|
||||
<icon BUILTIN="yes"/>
|
||||
<node CREATED="1718109979283" ID="ID_249817182" MODIFIED="1718109999348" TEXT="kann Inhalte aus einem Iterator kopieren"/>
|
||||
|
|
@ -83080,12 +83080,10 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718113039814" ID="ID_553490359" MODIFIED="1718118077881" TEXT="Implementierung durch Delegation">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718118079617" ID="ID_786279389" LINK="#ID_748929457" MODIFIED="1718118116331" TEXT="Testen mit allen Schikanen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1718113039814" ID="ID_553490359" MODIFIED="1718146528752" TEXT="Implementierung durch Delegation">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1718118079617" ID="ID_786279389" LINK="#ID_748929457" MODIFIED="1718147534164" TEXT="Testen mit allen Schikanen"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716936138265" ID="ID_344813639" MODIFIED="1716936143886" TEXT="Allokations-Policies">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
@ -83096,6 +83094,18 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718147554244" ID="ID_1260306723" MODIFIED="1718147566635" TEXT="convenience-Functions">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1718147568653" ID="ID_175737075" MODIFIED="1718147586344" TEXT="makeSeveral ( initializer_list )">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1718147641688" ID="ID_866349389" MODIFIED="1718147693481" TEXT="makeSeveral<TY> (elms...)">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1718147675355" ID="ID_1373098366" MODIFIED="1718147685899" TEXT="sinnvolle Syntax für Allokator??">
|
||||
<icon BUILTIN="help"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -83308,11 +83318,36 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1716857382441" ID="ID_748929457" MODIFIED="1718118121268" TEXT="check_Builder">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1718118125770" ID="ID_1218727200" MODIFIED="1718118149459" TEXT="Container Basistyp + beliebige Subklassen"/>
|
||||
<node CREATED="1718122126403" ID="ID_749733199" MODIFIED="1718122206871" TEXT="Basistyp und beliebiger Typ ⟹ wilder cast"/>
|
||||
<node CREATED="1718122626451" ID="ID_142448404" MODIFIED="1718122636499" TEXT="Iterator einfüllen"/>
|
||||
<node COLOR="#338800" CREATED="1716857382441" ID="ID_748929457" MODIFIED="1718147519927" TEXT="check_Builder">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1718118125770" ID="ID_1218727200" MODIFIED="1718146644299" TEXT="Container Basistyp + beliebige Subklassen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1718122126403" ID="ID_749733199" MODIFIED="1718146646198" TEXT="Basistyp und beliebiger Typ ⟹ wilder cast">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1718146547267" ID="ID_123092435" MODIFIED="1718146584184" TEXT="ein wildes Beispiel ist gar nicht so einfach....">
|
||||
<icon BUILTIN="smiley-oh"/>
|
||||
</node>
|
||||
<node CREATED="1718146553609" ID="ID_543025538" MODIFIED="1718146642666" TEXT="kann kein char[] direkt erstellen">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...und zwar, weil man ein (language)-Array mit operator new[] allozieren muß
|
||||
</p>
|
||||
<p>
|
||||
...✔ OK — selber schuld
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1718122626451" ID="ID_142448404" MODIFIED="1718147515497" TEXT="Iterator einfüllen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1716857382441" ID="ID_610081580" MODIFIED="1716857402102" TEXT="check_ErrorHandling">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue