Something does not come to mind how to make linear inheritance of classes (for example, A-> B-> C-> D) so that it would be possible to swap them in any sequence.
Pseudo code ( Not working ):
template <typename Impl> struct Base {}; template <template <typename> Impl, typename Tag> struct Base <Impl<Tag>> {}; template <typename Impl, template <typename...> typename ... Basics> struct A{}; template <template <typename> typename Impl, typename Tag, template <typename...> typename Base, template <typename...> typename ... Basics> struct A <Impl<Tag>, Base, Basics...> : public Base<Impl<Tag>, Basics ...>{}; template <typename Impl, template <typename...> typename ... Basics> struct B{}; template <template <typename> typename Impl, typename Tag, template <typename...> typename Base, template <typename...> typename ... Basics> struct B <Impl<Tag>, Base, Basics...> : public Base<Impl<Tag>, Basics ...>{}; template <typename Tag> struct C : public B<С<Tag>, A, Base> {};
Although I thought it should work, but no. In the example above, C-> B-> A-> Base was expected.
Assumption: There is an option that in specializations of classes А
and В
last template pack accepts only templates, which in turn accept only full types.
Addition: There is a hierarchy of static polymorphism, CRTP tobish. I need to create a hierarchy, for example, A inherits B, B inherits C, C inherits basic CRTP. Through template functions, you can call any class from this hierarchy. It is necessary to make it so that I can compose any class that inherits any chain that does not contradict the basic CRTP (I could call Tobish methods of this class). THOSE. There are 3 classes A, B and C that implement the CRTP contract and I could make a class D, which in any sequence can inherit these classes, with the condition that the final one is the CRTP base. Example: D-> A-Base, D-> C-> B-> Base and so on.
A more detailed example Without constructors, only class A
(By analogy, class B
, C
and so on. And without other sweets):
template <typename Impl> template Base { protected: template <typename Implementation> struct Accessor : public Implementation { template <typename SomeSpec, typename ... Args> static decltype(auto) some_spec(Implement* impl, SomeSpec&& some_spec, Args&& ... args) { return ::std::invoke(&Implement::some_spec_impl, impl, ::std::forward<SomeSpec>(some_spec), ::std::forward<Args>(args)...); } }; private: using Access = Accessor<Impl>; public: template <typename ... Args> decltype(auto) some_spec(Args&& ... args) { return Access::some_spec(static_cast<Impl*>(this), ::std::forward<Args>(args)...); } }; template <typename Impl> struct Base_spec{}; template <template <typename> class Impl, typename Tag> struct Base_spec<Impl<Tag>> : public Base<Impl<Tag>> { protected: template <typename Impl> using Accessor = typename Base<Impl<Tag>>:: template Accessor<Impl>; protected: decltype(auto) some_spec_impl(Some_spec spec) { // work and return something } }; template <typename Impl> struct A : public Base_spec<Impl> { private: template <typename Impl> using Accessor = typename Base_spec<Impl>:: template Accessor<Impl>; using Access = Accessor<Base_spec<Impl>>; protected: decltype(auto) some_spec_impl(Some_spec spec) { // some work return Access::some_spec(static_cast<Base_spec<Impl>*>(this), spec); } }
Accordingly, I wanted to give the opportunity to inherit not only from the individual classes А
, which implements its functionality, B
, which implements its own and inherits A
And, for example, functionality only from B
I am not asking you to do this, just indicate the errors in the first example, using the hierarchy from the second as an example.
Now classes are successively inherited: D-> C-> B-> A-> Base , which I would like to exclude.
std::tuple
, not - VTTtuple
? - MrBin pm