From 044a69cd7803410a77c9e40bc58321fb1def010d Mon Sep 17 00:00:00 2001 From: Luke Valenty Date: Sun, 24 Apr 2022 14:42:33 -0700 Subject: [PATCH] workaround bugs in clang and gcc to optimize compiled efficiency (#51) resolves #50 --- include/cib/nexus.hpp | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/include/cib/nexus.hpp b/include/cib/nexus.hpp index 41118009..a2941250 100644 --- a/include/cib/nexus.hpp +++ b/include/cib/nexus.hpp @@ -24,47 +24,33 @@ namespace cib { template struct nexus { private: - template - using raw_service_t = decltype(initialized::value.template build>()); - - template - CIB_CONSTINIT static inline raw_service_t raw_service = - initialized::value.template build>(); + using this_t = nexus; template using service_name_to_raw_type_t = typename std::remove_const_t(cib::initialized_builders_v))>>; - template - using service_t = - decltype(initialized>::value.template build>>()); + // Workaround unfortunate bug in clang where it can't deduce "auto" sometimes + #define CIB_BUILD_SERVICE initialized>::value.template build>>() public: template - CIB_CONSTINIT static inline service_t service = - initialized>::value.template build>>(); + constexpr static decltype(CIB_BUILD_SERVICE) service = CIB_BUILD_SERVICE; + #undef CIB_BUILD_SERVICE static void init() { detail::for_each(initialized_builders_v, [](auto b){ - // Tag/CleanTag is the type name of the builder_meta in the ordered_set - using Tag = typename decltype(b)::Service; - using CleanTag = std::remove_cv_t>; - - using CleanTypename = std::remove_cv_t>; + using service_tag = typename decltype(b)::Service; + using clean_service_tag = std::remove_cv_t>; - // the built implementation is stored in Build<>::value - auto & builtValue = raw_service; - using BuiltType = std::remove_reference_t; + auto & service_impl = this_t::service; + using service_impl_type = std::remove_reference_t; - // if the built type is a pointer, then it is a function pointer and we should return its value - // directly to the 'built<>' abstract interface variable. - if constexpr(std::is_pointer_v) { - cib::service = builtValue; + if constexpr(std::is_pointer_v) { + cib::service = service_impl; - // if the built type is not a pointer, then it is a class and the 'built<>' variable is a pointer to - // the base class. we will need to get a pointer to the builtValue in order to initialize 'built<>'. } else { - cib::service = &builtValue; + cib::service = &service_impl; } }); }