From f4924871e2459714680e25fc3de268d80d6f3778 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 22 Jul 2018 11:52:33 +0200 Subject: main-window: further work --- main-window/CMakeLists.txt | 2 +- main-window/mixin-traits.cpp | 41 ++++++++++++++++++++++++++++++++--------- main-window/mixin-traits.hpp | 41 ++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/main-window/CMakeLists.txt b/main-window/CMakeLists.txt index 3edd241b..f69080f1 100644 --- a/main-window/CMakeLists.txt +++ b/main-window/CMakeLists.txt @@ -1,4 +1,4 @@ -otr_module(main-window BIN) +otr_module(main-window BIN NO-INSTALL) foreach(k user-interface logic pose-widget migration spline) target_link_libraries(${self} opentrack-${k}) endforeach() diff --git a/main-window/mixin-traits.cpp b/main-window/mixin-traits.cpp index ea8e9bc8..5dc2efd8 100644 --- a/main-window/mixin-traits.cpp +++ b/main-window/mixin-traits.cpp @@ -1,22 +1,27 @@ -//#define MIXIN_TRAIT_TESTS +#define MIXIN_TRAIT_TESTS #ifdef MIXIN_TRAIT_TESTS # include "mixin-traits.hpp" +// the `impl' class provides a cast template through the CRTP pattern. +// mixins don't do direct inheritance on themselves, +// that's what mixin_traits::depends is for. + namespace mixins::traits_detail { struct A {}; -struct B : A {}; +struct B {}; struct C {}; +struct D {}; -template<> struct mixin_traits +template<> struct mixin_traits { - using depends = tuple; + using depends = tuple<>; }; -template<> struct mixin_traits +template<> struct mixin_traits { - using depends = tuple<>; + using depends = tuple; }; template<> struct mixin_traits @@ -24,13 +29,31 @@ template<> struct mixin_traits using depends = tuple; }; +template<> struct mixin_traits +{ + using depends = tuple; +}; + extern void test1(); void test1() { - //impl fail1; - impl ok1; - impl ok2; + struct U : B, A {}; + struct V : D {}; + struct W : C, A {}; + struct Q : virtual W, virtual D {}; + +#if 0 + (void)impl(); // W not a mixin + (void)impl(); // A + (void)impl(); // D => C => A + (void)impl(); // D => C => A + (void)impl(); // B +#else + (void)impl(); + (void)impl(); + (void)impl(); +#endif } } // ns mixins::traits_detail diff --git a/main-window/mixin-traits.hpp b/main-window/mixin-traits.hpp index 84a64d08..6a0206fc 100644 --- a/main-window/mixin-traits.hpp +++ b/main-window/mixin-traits.hpp @@ -1,7 +1,5 @@ #pragma once -#include "compat/linkage-macros.hpp" -#include "compat/macros.hpp" #include "compat/meta.hpp" #include @@ -9,40 +7,41 @@ namespace mixins::traits_detail { using namespace meta; - template - using tuple = meta::detail::tuple; + + template using tuple = tuple_; template struct mixin_traits { - //using depends = tuple<>; + // implement this! + using depends = tuple<>; + + // unconditional but at instantiation time + static_assert(sizeof(t) < sizeof(char), + "must specialize mixin_traits"); }; template struct check_depends_; template - struct check_depends_ + struct check_depends_ : std::true_type { - using type = std::bool_constant; }; template - struct check_depends_ + struct check_depends_ : + std::bool_constant< + std::is_base_of_v && + lift::depends>>::value && + check_depends_::value + > { - using b1 = std::is_base_of; - using b2 = typename check_depends_::type; - - using depends = typename mixin_traits::depends; - using t1 = cons; - using t2 = lift; - using b3 = typename t2::type; - - using type = std::bool_constant; }; - template - class impl + template + struct impl { - using t1 = typename lift::depends>>::type; - static_assert(t1::value); + static constexpr bool class_must_inherit_dependent_mixins = + lift>::value; + static_assert(class_must_inherit_dependent_mixins); }; } // ns mixins::traits_detail -- cgit v1.2.3