RemoveReferenceWrapper.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <functional>
7 
8 #include "Utilities/TypeTraits.hpp"
9 
10 namespace tt {
11 // @{
12 /*!
13  * \ingroup TypeTraitsGroup
14  * \brief Gets the underlying type if the type is a std::reference_wrapper,
15  * otherwise returns the type itself
16  *
17  * \usage
18  * For any type `I`,
19  * \code
20  * using result = tt::remove_reference_wrapper<I>;
21  * \endcode
22  * \metareturns
23  * either `I::type` if `I` is a std::reference_wrapper, else returns I
24  *
25  * \example
26  * \snippet Test_RemoveReferenceWrapper.cpp remove_reference_wrapper_example
27  * \see std::reference_wrapper
28  */
29 template <typename T>
31  using type = T;
32 };
33 
34 /// \cond HIDDEN_SYMBOLS
35 template <typename T>
36 struct remove_reference_wrapper<std::reference_wrapper<T>> {
37  using type = T;
38 };
39 
40 template <typename T>
41 struct remove_reference_wrapper<const std::reference_wrapper<T>> {
42  using type = T;
43 };
44 
45 template <typename T>
46 struct remove_reference_wrapper<volatile std::reference_wrapper<T>> {
47  using type = T;
48 };
49 
50 template <typename T>
51 struct remove_reference_wrapper<const volatile std::reference_wrapper<T>> {
52  using type = T;
53 };
54 /// \endcond
55 
56 template <typename T>
57 using remove_reference_wrapper_t = typename remove_reference_wrapper<T>::type;
58 // @}
59 
60 // @{
61 /*!
62  * \ingroup TypeTraitsGroup
63  * \brief Removes std::reference_wrapper, references, and cv qualifiers.
64  *
65  * \example
66  * \snippet Test_RemoveReferenceWrapper.cpp remove_cvref_wrap
67  * \see std::reference_wrapper remove_reference_wrapper std::remove_cvref
68  */
69 template <typename T>
71  using type = cpp20::remove_cvref_t<tt::remove_reference_wrapper_t<T>>;
72 };
73 
74 template <typename T>
75 using remove_cvref_wrap_t = typename remove_cvref_wrap<T>::type;
76 // @}
77 } // namespace tt
functional
tt::remove_cvref_wrap
Removes std::reference_wrapper, references, and cv qualifiers.
Definition: RemoveReferenceWrapper.hpp:70
tt::remove_reference_wrapper
Gets the underlying type if the type is a std::reference_wrapper, otherwise returns the type itself.
Definition: RemoveReferenceWrapper.hpp:30
tt
Definition: TensorExpression.hpp:168