diff --git a/Utilities/typemap.h b/Utilities/typemap.h index e0d6a04e56..0f4b823485 100644 --- a/Utilities/typemap.h +++ b/Utilities/typemap.h @@ -113,21 +113,6 @@ namespace utils static_assert(ullong{max_count} * typeinfo_step::step <= 0x1'0000'0000ull); }; - // Detect polymorphic type enablement - template - struct typeinfo_poly - { - static constexpr bool is_poly = false; - }; - - template - struct typeinfo_poly::id_poly)>> - { - static constexpr bool is_poly = true; - - static_assert(std::has_virtual_destructor_v>); - }; - // Detect operator -> template struct typeinfo_pointer @@ -202,27 +187,12 @@ namespace utils static void call_destructor(class typemap_block* ptr); typeinfo(); - - template - friend struct typepoly; }; // Type information for each used type template inline const typeinfo g_typeinfo{}; - template - struct typepoly - { - uint type = 0; - - typepoly(); - }; - - // Polymorphic type helper - template - inline const typepoly g_typepoly{}; - template typeinfo::typeinfo() { @@ -274,43 +244,6 @@ namespace utils } } - template - typepoly::typepoly() - { - static_assert(alignof(T) < 4096); - - if (this != &g_typepoly) - { - // Protect global state against unrelated constructions of typepoly<> objects - return; - } - - // Set min align 16 to make some space for a pointer - const uint size{sizeof(T) < 16 ? 16 : sizeof(T)}; - const uint align{alignof(T) < 16 ? 16 : alignof(T)}; - - typeinfo_base& info = const_cast&>(g_typeinfo); - - this->type = info.type; - - // Update max size and alignment of the base class typeinfo - if (info.size < size) - info.size = size; - if (info.align < align) - info.align = align; - - if constexpr (typeinfo_share::is_shared) - { - typeinfo_base& base = const_cast(*info.base); - - // Update max size and alignment of the shared type - if (base.size < size) - base.size = size; - if (base.align < align) - base.align = align; - } - } - // Internal, control block for a particular object class typemap_block { @@ -341,16 +274,7 @@ namespace utils template void typeinfo::call_destructor(typemap_block* ptr) { - // Choose cleanup routine - if constexpr (typeinfo_poly::is_poly) - { - // Read actual pointer to the base class - (*ptr->get_ptr())->~T(); - } - else - { - ptr->get_ptr()->~T(); - } + ptr->get_ptr()->~T(); } // An object of type T paired with atomic refcounter @@ -584,15 +508,7 @@ namespace utils auto get() const noexcept { ASSUME(m_block->m_type != 0); - - if constexpr (std::is_lvalue_reference_v) - { - return static_cast(*m_block->get_ptr*>()); - } - else - { - return m_block->get_ptr(); - } + return m_block->get_ptr(); } auto operator->() const noexcept @@ -648,19 +564,7 @@ namespace utils } } - if constexpr (std::is_lvalue_reference_v) - { - using base = std::remove_reference_t; - - if (m_block->m_type.exchange(g_typepoly.type) != 0) - { - (*m_block->get_ptr())->~base(); - m_head->m_destroy_count++; - } - - *m_block->get_ptr() = new (m_block->get_ptr()) New(std::forward(args)...); - } - else + if constexpr (true) { static_assert(std::is_same_v); @@ -688,16 +592,7 @@ namespace utils return; } - if constexpr (std::is_lvalue_reference_v) - { - using base = std::remove_reference_t; - (*m_block->get_ptr())->~base(); - } - else - { - m_block->get_ptr()->~T(); - } - + m_block->get_ptr()->~T(); m_head->m_destroy_count++; } @@ -988,14 +883,7 @@ namespace utils if (block->m_type == type_id) { - if constexpr (std::is_lvalue_reference_v) - { - if (std::invoke(std::forward(id), std::as_const(**block->get_ptr*>()))) - { - break; - } - } - else if (std::invoke(std::forward(id), std::as_const(*block->get_ptr()))) + if (std::invoke(std::forward(id), std::as_const(*block->get_ptr()))) { break; } @@ -1089,16 +977,7 @@ namespace utils // Initialize object if necessary static_assert(!std::is_const_v>); static_assert(!std::is_volatile_v>); - - if constexpr (std::is_lvalue_reference_v) - { - using base = std::remove_reference_t; - *block->get_ptr() = new (block->get_ptr()) base(); - } - else - { - new (block->get_ptr) Type(); - } + new (block->get_ptr) Type(); } return; @@ -1112,14 +991,7 @@ namespace utils if (LIKELY(block->m_type == type_id)) { - if constexpr (std::is_lvalue_reference_v) - { - if (std::invoke(std::forward(id), std::as_const(**block->get_ptr*>()))) - { - return; - } - } - else if (std::invoke(std::forward(id), std::as_const(*block->get_ptr()))) + if (std::invoke(std::forward(id), std::as_const(*block->get_ptr()))) { return; } @@ -1293,7 +1165,7 @@ namespace utils template > auto lock(Args&&... ids) const { - static_assert(((!std::is_lvalue_reference_v == !typeinfo_poly::is_poly) && ...)); + static_assert(((!std::is_lvalue_reference_v) && ...)); static_assert(((!std::is_array_v) && ...)); static_assert(((!std::is_void_v) && ...)); @@ -1332,7 +1204,7 @@ namespace utils template ullong apply(F&& func) { - static_assert(!std::is_lvalue_reference_v == !typeinfo_poly::is_poly); + static_assert(!std::is_lvalue_reference_v); static_assert(!std::is_array_v); static_assert(!std::is_void_v); @@ -1352,14 +1224,7 @@ namespace utils if (block->m_type == type_id) { - if constexpr (std::is_lvalue_reference_v) - { - std::invoke(std::forward(func), **block->get_ptr*>()); - } - else - { - std::invoke(std::forward(func), *block->get_ptr>()); - } + std::invoke(std::forward(func), *block->get_ptr>()); } } }