From 678fc660d9a58a3258e649a5b5070145938041d1 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Tue, 26 May 2020 17:36:49 -0500 Subject: [PATCH] Workaround: Make this work with std::vector> --- include/deal.II/base/thread_local_storage.h | 41 ++++++++++++++++----- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/include/deal.II/base/thread_local_storage.h b/include/deal.II/base/thread_local_storage.h index 3c0e6335c6..90784d542f 100644 --- a/include/deal.II/base/thread_local_storage.h +++ b/include/deal.II/base/thread_local_storage.h @@ -34,6 +34,30 @@ DEAL_II_NAMESPACE_OPEN namespace Threads { +# ifndef DOXYGEN + namespace + { + /* + * Workaround: The standard unfortunately has a flaw in the type traits + * when it comes to std::is_copy_constructible and a std::vector + * containing non-copyable objects T. The type trait is true even + * though any attempted invocation leads to a compilation error. Work + * around this issue by removing the "std::vector" container from the + * type trait. + */ + template + struct unpack_vector + { + using type = T; + }; + template + struct unpack_vector> + { + using type = T; + }; + } // namespace +# endif + /** * @brief A class that provides a separate storage location on each thread * that accesses the object. @@ -65,7 +89,7 @@ namespace Threads class ThreadLocalStorage { static_assert( - std::is_copy_constructible::value || + std::is_copy_constructible::type>::value || std::is_default_constructible::value, "The stored type must be either copyable, or default constructible"); @@ -191,7 +215,7 @@ namespace Threads /** * An exemplar for creating a new (thread specific) copy. */ - std::shared_ptr exemplar; + std::shared_ptr exemplar; }; } // namespace Threads /** @@ -210,16 +234,14 @@ namespace Threads template inline ThreadLocalStorage::ThreadLocalStorage(const T &t) - { - exemplar = std::make_shared(t); - } + : exemplar(std::make_shared(t)) + {} template inline ThreadLocalStorage::ThreadLocalStorage(T &&t) - { - exemplar = std::make_shared(std::forward(t)); - } + : exemplar(std::make_shared(std::forward(t))) + {} template @@ -258,7 +280,8 @@ namespace Threads // std::unique_lock lock(insertion_mutex); - if constexpr (std::is_copy_constructible::value) + if constexpr (std::is_copy_constructible< + typename unpack_vector::type>::value) if (exemplar) { const auto it = data.emplace(my_id, *exemplar).first; -- 2.39.5