diff --git a/research/try.cpp b/research/try.cpp index 979816cf6..d722f412c 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -70,7 +70,12 @@ typedef unsigned int uint; int main (int, char**) { + std::srand(std::time(nullptr)); +// DependInject::useSingleton ([&] { return "long{rand() % 100}"; }); +// DependInject::Local dummy ([&]{ return new long{rand() % 100}; }); + + cout << "rrrrrr.."<< Depend{}() <::value, "Need a Lambda or Function object to create a heap allocated instance"); - - using Ret = typename _Fun::Ret; - using Sub = typename Strip::TypePlain; - + using Sub = typename SubclassFactory::Sub; __assert_compatible(); - static_assert (std::is_pointer::value, "Function must yield a pointer to a heap allocated instance"); static InstanceHolder singleton; installFactory ([ctor]() @@ -199,6 +191,8 @@ namespace lib { Local (FUN&& buildInstance) { __assert_compatible(); + __assert_compatible::Sub>(); + temporarilyInstallAlternateFactory (origInstance_, origFactory_ ,[=]() { @@ -249,10 +243,24 @@ namespace lib { static void __assert_compatible() { - static_assert (std::is_base_of::value, - "Installed implementation class must be compatible to the interface."); + static_assert (meta::is_Subclass() + ,"Installed implementation class must be compatible to the interface."); } + template + struct SubclassFactory + { + static_assert (meta::_Fun(), + "Need a Lambda or Function object to create a heap allocated instance"); + + using Res = typename meta::_Fun::Ret; + using Sub = typename meta::Strip::TypePlain; + + static_assert (std::is_pointer::value, + "Function must yield a pointer to a heap allocated instance"); + }; + + static void installFactory (Factory&& otherFac) { diff --git a/src/lib/meta/trait.hpp b/src/lib/meta/trait.hpp index e100a8f14..d82364655 100644 --- a/src/lib/meta/trait.hpp +++ b/src/lib/meta/trait.hpp @@ -94,12 +94,15 @@ namespace meta { using std::remove_cv; using std::remove_pointer; using std::remove_reference; + using std::is_pointer; + using std::is_base_of; using std::is_convertible; using std::is_constructible; using std::is_floating_point; using std::is_arithmetic; using std::is_unsigned; using std::is_signed; + using std::is_class; using std::is_same; using std::__not_; using std::__and_; @@ -270,6 +273,17 @@ namespace meta { ,typename Strip::TypeReferred> { }; + /** verify compliance to an interface by subtype check */ + template + struct is_Subclass + : __or_< __and_< is_class + , is_class + , is_base_of + > + , is_same + > + { }; + /** detect various flavours of string / text data */ template struct is_StringLike @@ -311,8 +325,8 @@ namespace meta { /** when to use custom string conversions for output streams */ template struct use_StringConversion4Stream - : __and_::TypePlain> - ,__not_> + : __and_::TypePlain> + ,__not_> ,__not_> > { }; diff --git a/src/lib/scoped-collection.hpp b/src/lib/scoped-collection.hpp index 06b8e4ba9..94baf2549 100644 --- a/src/lib/scoped-collection.hpp +++ b/src/lib/scoped-collection.hpp @@ -70,6 +70,7 @@ #include "lib/error.hpp" +#include "lib/meta/trait.hpp" #include "lib/iter-adapter.hpp" #include @@ -136,8 +137,7 @@ namespace lib { TY& create (ARGS&& ...args) { - static_assert ( (std::is_same::value - ||std::is_base_of::value) + static_assert ( meta::is_Subclass() && sizeof(TY) <= siz, "ElementHolder buffer to small"); diff --git a/src/lib/test/suite.cpp b/src/lib/test/suite.cpp index 3b3955e1d..c2c8b4b85 100644 --- a/src/lib/test/suite.cpp +++ b/src/lib/test/suite.cpp @@ -151,7 +151,7 @@ namespace test { TRACE(test, "Test-Suite( groupID=%s )\n", groupID.c_str () ); // Seed random number generator - std::srand (std::time (NULL)); + std::srand (std::time (nullptr)); if (!testcases.getGroup(groupID)) throw lumiera::error::Invalid ("empty testsuite"); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 53d7d1c17..060263325 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -26601,8 +26601,7 @@ Bei diesem Wunsch-Profil bleibt nur eine Variante von Lösung-2

- - + @@ -26612,8 +26611,7 @@ ...denn nur eine dynamische Laufzeit-Factory ermöglicht, jederzeit  den Konstruktionsmodus zu wechseln

- -
+ @@ -26658,8 +26656,7 @@ - - + @@ -26677,8 +26674,7 @@ Freiheit der dynamischen Laufzeit-Konfiguration verlieren.

- -
+
@@ -26693,8 +26689,7 @@ und die konventionelle Lösung hat demgegenüber den Vorteil, daß sie Struktur und Kontrakt explizit macht.

- -
+
@@ -26723,8 +26718,7 @@ - - + @@ -26755,8 +26749,7 @@ scheidet für unser Nutzungsmuster aus

- - + @@ -26772,8 +26765,7 @@ wieder auf NULL zurücksetzen zu können.

- -
+ @@ -26836,8 +26828,7 @@ wenn die DependInject-Instanz stirbt

- - + @@ -26858,8 +26849,7 @@ sie werden ja sofort ausgewertet, da die Service-Instanz unmittelbar gebaut wird

- - +
@@ -26908,7 +26898,8 @@ - + + @@ -26928,8 +26919,7 @@ aber Lebenszyklus ist an die Factory gebunden

- - +
@@ -27017,8 +27007,7 @@ Har Har Har! Selber schuld wer sowas macht.

- - +
@@ -27085,8 +27074,7 @@ statische Storage ist irgendwie cool

- - + @@ -27111,8 +27099,7 @@ selbst wenn die dynamische Konfiguration so angelegt ist, daß die Storage nie benötigt wird

- - +
@@ -27143,8 +27130,7 @@ ...aber dann eben nicht mehr elegant.

- - +
@@ -27196,8 +27182,7 @@ In Zukunft könnten Compiler/Linker noch "schlauer" werden...

- - +
@@ -27244,8 +27229,8 @@ - - + + @@ -27272,8 +27257,7 @@ konstruieren wollen könnte, und es ist von der Implementierung her "quasi geschenkt".

- -
+
@@ -27365,8 +27349,7 @@ und heute würde ich den Code so nicht mehr schreiben

- - +