#include <cassert>
// Abstracte Interfaces ueber DLL-Grenze per Id zuordnen - so eine Art COM-Interface fuer arme Leute
// abstract Base
struct Base
{
};
// abstract Interfaces
struct InterfaceA{};
struct InterfaceB{};
struct InterfaceC{};
// Interface-Type zu Id mapping
template<typename Type> struct InterfaceId {};
template<> struct InterfaceId<InterfaceA>{ static constexpr int id = 0; };
template<> struct InterfaceId<InterfaceB>{ static constexpr int id = 1; };
template<> struct InterfaceId<InterfaceC>{ static constexpr int id = 2; };
template<typename... Interface>
struct Test: Base
{
Base* implements(int id)
{
// <-- wie kann man dieses If mit C++17 aus dem Interface-Parameter pack generieren lassen?
if( id == InterfaceId<InterfaceA>::id
|| id == InterfaceId<InterfaceC>::id ) return this;
return nullptr;
}
};
int main()
{
Test<InterfaceA,InterfaceC> t;
assert(t.implements(InterfaceId<InterfaceA>::id));
assert(!t.implements(InterfaceId<InterfaceB>::id));
return 0;
}