CanBeCopyConstructed.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <type_traits>
7 
8 #include "Utilities/TypeTraits.hpp"
9 
10 namespace tt {
11 // @{
12 /*!
13  * \ingroup TypeTraitsGroup
14  * \brief Check if `T` is copy constructible
15  *
16  * The STL `std::is_copy_constructible` does not work as expected with some
17  * types, such as `std::unordered_map`. This is because
18  * `std::is_copy_constructible` only checks that the copy construction call is
19  * well-formed, not that it could actually be done in practice. To get around
20  * this for containers we check that `T::value_type` is also copy constructible.
21  */
22 template <typename T, typename = void>
24 
25 /// \cond
26 template <typename T>
27 struct can_be_copy_constructed<T, cpp17::void_t<typename T::value_type>>
29  cpp17::is_copy_constructible_v<T> and
30  cpp17::is_copy_constructible_v<typename T::value_type>> {};
31 /// \endcond
32 
33 template <typename T>
34 constexpr bool can_be_copy_constructed_v = can_be_copy_constructed<T>::value;
35 // @}
36 } // namespace tt
void void_t
Given a set of types, returns void
Definition: TypeTraits.hpp:187
Check if T is copy constructible.
Definition: CanBeCopyConstructed.hpp:23
A collection of useful type traits.
Definition: TensorExpression.hpp:113