diff --git a/python/templates/Interface.h.jinja2 b/python/templates/Interface.h.jinja2 index 299bbfb10..953ec24ab 100644 --- a/python/templates/Interface.h.jinja2 +++ b/python/templates/Interface.h.jinja2 @@ -92,10 +92,10 @@ private: std::unique_ptr m_self{nullptr}; public: - template + // {{ class.bare_type }} can only be initialized with one of the following types (and their Mutable counter parts): {{ Types | join(", ") }} + template>> {{ class.bare_type }}(ValueT value) : m_self(std::make_unique>>(value)) { - static_assert(isInitializableFrom, "{{ class.bare_type }} can only be initialized with one of the following types (and their Mutable counter parts): {{ Types | join(", ") }}"); } {{ class.bare_type }}(const {{ class.bare_type }}& other) : diff --git a/tests/unittests/interface_types.cpp b/tests/unittests/interface_types.cpp index 00fdd0352..49f31babd 100644 --- a/tests/unittests/interface_types.cpp +++ b/tests/unittests/interface_types.cpp @@ -1,7 +1,9 @@ #include "catch2/catch_test_macros.hpp" +#include "datamodel/ExampleHit.h" #include "datamodel/ExampleHitCollection.h" #include "datamodel/MutableExampleCluster.h" +#include "datamodel/MutableExampleMC.h" #include "datamodel/TypeWithEnergy.h" #include "podio/ObjectID.h" @@ -9,6 +11,8 @@ #include #include +#include +#include TEST_CASE("InterfaceTypes basic functionality", "[interface-types][basics]") { using WrapperT = TypeWithEnergy; @@ -67,6 +71,16 @@ TEST_CASE("InterfaceTypes STL usage", "[interface-types][basics]") { REQUIRE(counterMap[empty] == 1); REQUIRE(counterMap[hit] == 2); REQUIRE(counterMap[wrapper] == 2); + + auto mc = MutableExampleMC{}; + mc.energy() = 3.14f; + + // check container of interfaces move constructor and direct initialization + auto interfaces = std::vector{empty, hit, mc}; + auto interfaces2 = std::vector{std::move(interfaces)}; + REQUIRE_FALSE(interfaces2.at(0).isAvailable()); + REQUIRE(interfaces2.at(1).isA()); + REQUIRE(interfaces2.at(2).energy() == 3.14f); } TEST_CASE("InterfaceType from immutable", "[interface-types][basics]") {