From: Matthias Maier Date: Tue, 26 May 2020 22:36:49 +0000 (-0500) Subject: Workaround: Make this work with std::vector> X-Git-Tag: v9.3.0-rc1~1535^2~8 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=678fc660d9a58a3258e649a5b5070145938041d1;p=dealii.git Workaround: Make this work with std::vector> --- 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;