From 5fe90a6810ff4615beab16455753e376316f4673 Mon Sep 17 00:00:00 2001 From: Liss Heidrich <31625940+Clueliss@users.noreply.github.com> Date: Mon, 18 Mar 2024 08:59:32 +0100 Subject: [PATCH] fix extern template instantiation --- include/dice/template-library/flex_array.hpp | 34 +++++++++++--------- tests/tests_flex_array.cpp | 9 ++++++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/include/dice/template-library/flex_array.hpp b/include/dice/template-library/flex_array.hpp index 954bfa5..6dcd389 100644 --- a/include/dice/template-library/flex_array.hpp +++ b/include/dice/template-library/flex_array.hpp @@ -11,6 +11,24 @@ namespace dice::template_library { using std::dynamic_extent; + namespace detail_flex_array { + template + struct flex_array_inner { + static constexpr size_t size_ = extent; + std::array data_; + + constexpr auto operator<=>(flex_array_inner const &) const noexcept = default; + }; + + template + struct flex_array_inner { + size_t size_ = 0; + std::array data_; + + constexpr auto operator<=>(flex_array_inner const &) const noexcept = default; + }; + } // namespace detail_flex_array + /** * A combination of std::array and std::span. * If extent_ is set to some integer value (!= dynamic_extent), flex_array behaves like std::array, i.e. has a fixed, statically known size, max_size/capacity. @@ -32,21 +50,7 @@ namespace dice::template_library { static constexpr bool is_dynamic_extent = extent == dynamic_extent; private: - struct inner_type_fixed { - static constexpr size_t size_ = extent; - std::array data_; - - constexpr auto operator<=>(inner_type_fixed const &) const noexcept = default; - }; - - struct inner_type_dynamic { - size_t size_ = 0; - std::array data_; - - constexpr auto operator<=>(inner_type_dynamic const &) const noexcept = default; - }; - - using inner_type = std::conditional_t; + using inner_type = detail_flex_array::flex_array_inner; public: using value_type = T; diff --git a/tests/tests_flex_array.cpp b/tests/tests_flex_array.cpp index 5b9c393..1a24f83 100644 --- a/tests/tests_flex_array.cpp +++ b/tests/tests_flex_array.cpp @@ -5,6 +5,15 @@ #include #include +namespace dice::template_library { + // extern template sometimes make problems if internal types are too eagerly instantiated + extern template struct flex_array; + extern template struct flex_array; + + template struct flex_array; + template struct flex_array; +} // namespace dice::template_library + TEST_SUITE("flex_array") { using namespace dice::template_library;