TagTraits.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <type_traits>
8 
9 #include "Utilities/Requires.hpp"
10 #include "Utilities/TypeTraits.hpp"
11 
12 /// \cond
13 namespace db {
14 struct SimpleTag;
15 struct BaseTag;
16 struct ComputeTag;
17 } // namespace db
18 /// \endcond
19 
20 namespace db {
21 // @{
22 /*!
23  * \ingroup DataBoxGroup
24  * \brief Check if `Tag` derives off of db::ComputeTag
25  */
26 template <typename Tag, typename = std::nullptr_t>
28 /// \cond HIDDEN_SYMBOLS
29 template <typename Tag>
30 struct is_compute_tag<Tag, Requires<std::is_base_of_v<db::ComputeTag, Tag>>>
31  : std::true_type {};
32 /// \endcond
33 
34 template <typename Tag>
35 constexpr bool is_compute_tag_v = is_compute_tag<Tag>::value;
36 // @}
37 
38 // @{
39 /*!
40  * \ingroup DataBoxGroup
41  * \brief Check if `Tag` is a non-base DataBox tag. I.e. a SimpleTag or a
42  * ComputeTag
43  */
44 template <typename Tag, typename = std::nullptr_t>
46 /// \cond
47 template <typename Tag>
48 struct is_non_base_tag<Tag, Requires<std::is_base_of_v<db::ComputeTag, Tag> or
49  std::is_base_of_v<db::SimpleTag, Tag>>>
50  : std::true_type {};
51 /// \endcond
52 
53 template <typename Tag>
54 constexpr bool is_non_base_tag_v = is_non_base_tag<Tag>::value;
55 // @}
56 
57 // @{
58 /*!
59  * \ingroup DataBoxGroup
60  * \brief Check if `Tag` is a BaseTag, SimpleTag, or ComputeTag
61  */
62 template <typename Tag, typename = std::nullptr_t>
63 struct is_tag : std::false_type {};
64 /// \cond
65 template <typename Tag>
66 struct is_tag<Tag, Requires<std::is_base_of_v<db::ComputeTag, Tag> or
67  std::is_base_of_v<db::SimpleTag, Tag> or
68  std::is_base_of_v<db::BaseTag, Tag>>>
69  : std::true_type {};
70 /// \endcond
71 
72 template <typename Tag>
73 constexpr bool is_tag_v = is_tag<Tag>::value;
74 // @}
75 
76 // @{
77 /*!
78  * \ingroup DataBoxGroup
79  * \brief Check if `Tag` is a base DataBox tag
80  */
81 template <typename Tag, typename = std::nullptr_t>
83 /// \cond HIDDEN_SYMBOLS
84 template <typename Tag>
85 struct is_base_tag<Tag, Requires<std::is_base_of_v<db::BaseTag, Tag> and
86  not std::is_base_of_v<db::SimpleTag, Tag> and
87  not is_compute_tag_v<Tag>>> : std::true_type {
88 };
89 /// \endcond
90 
91 template <typename Tag>
92 constexpr bool is_base_tag_v = is_base_tag<Tag>::value;
93 // @}
94 
95 } // namespace db
std::false_type
db::is_tag
Check if Tag is a BaseTag, SimpleTag, or ComputeTag.
Definition: TagTraits.hpp:63
db::is_non_base_tag
Check if Tag is a non-base DataBox tag. I.e. a SimpleTag or a ComputeTag.
Definition: TagTraits.hpp:45
db::is_compute_tag
Check if Tag derives off of db::ComputeTag.
Definition: TagTraits.hpp:27
cstddef
Requires.hpp
Requires
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Definition: Requires.hpp:67
type_traits
db
Namespace for DataBox related things.
Definition: DataBox.hpp:42
db::is_base_tag
Check if Tag is a base DataBox tag.
Definition: TagTraits.hpp:82