Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
traits.h
1 // NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2 // software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3 // derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4 // or works. Modified works should carry a notice stating that you changed the software and should note the date and
5 // nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6 // source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7 // EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9 // WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10 // CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11 // THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12 // are solely responsible for determining the appropriateness of using and distributing the software and you assume
13 // all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14 // with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15 // operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16 // damage to property. The software developed by NIST employees is not subject to copyright protection within the
17 // United States.
18 
19 
20 #ifndef HEDGEHOG_TRAITS_H
21 #define HEDGEHOG_TRAITS_H
22 
23 #include <type_traits>
24 #include <utility>
25 #include <string_view>
26 
27 #if defined( __GLIBCXX__ ) || defined( __GLIBCPP__ )
28 #include <cxxabi.h>
29 #endif
30 
31 
33 namespace hh {
34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
35 template<class T>
38 class MemoryData;
39 #endif //DOXYGEN_SHOULD_SKIP_THIS
40 
42 namespace traits {
43 
46 template<typename...>
47 inline constexpr auto isUnique = std::true_type{};
48 
52 template<typename T, typename... Rest>
53 inline constexpr auto isUnique<T, Rest...> =
54  std::bool_constant<(!std::is_same_v<T, Rest> && ...) && isUnique<Rest...>>{};
55 
58 template<class PossibleManagedMemory>
60  constexpr static bool const value =
61  std::is_base_of_v<MemoryData<PossibleManagedMemory>, PossibleManagedMemory>
62  && std::is_default_constructible_v<PossibleManagedMemory>;
63 };
66 
69 template<class PossibleManagedMemory>
71 
76 template<class T, class... Ts>
77 struct Contains {
78  constexpr static bool value = std::disjunction_v<std::is_same<T, Ts>...>;
79 };
80 
84 template<class T, class... Ts>
85 struct Contains<T, std::tuple<Ts...> > : Contains<T, Ts...> {};
86 
90 template<class T, class... Ts>
91 inline constexpr bool Contains_v = Contains<T, std::tuple<Ts...>>::value;
92 
97 template<class T1, class T2, class Is>
99 
104 template<class T1, class T2, std::size_t... Is>
105 struct _is_included_<T1, T2, std::integer_sequence<std::size_t, Is...> > {
106  static bool const
107  value = std::disjunction_v<Contains<typename std::tuple_element<Is, T1>::type, T2>...>;
108 };
110 
114 template<class T1, class T2>
115 struct is_included : _is_included_<T1, T2, std::make_integer_sequence<std::size_t, std::tuple_size<T1>::value> > {};
116 
120 template<class T1, class T2>
122 
126 template<typename T>
127 constexpr auto type_name() {
128  std::string_view name, prefix, suffix;
129 #ifdef __clang__
130  name = __PRETTY_FUNCTION__;
131  prefix = "auto hh::traits::type_name() [T = ";
132  suffix = "]";
133 #elif defined(__GNUC__)
134  name = __PRETTY_FUNCTION__;
135  prefix = "constexpr auto hh::traits::type_name() [with T = ";
136  suffix = "]";
137 #elif defined(_MSC_VER)
138  name = __FUNCSIG__;
139  prefix = "auto __cdecl hh::traits::type_name<";
140  suffix = ">(void)";
141 #endif
142  name.remove_suffix(suffix.size());
143  name.remove_prefix(prefix.size());
144  return name;
145 }
146 }
147 }
148 #endif //HEDGEHOG_TRAITS_H
static constexpr bool const value
True if PossibleManagedMemory can be handled by an AbstractMemoryManager, else False.
Definition: traits.h:60
Hedgehog main namespace.
constexpr auto isUnique
Check if all parameters in a parameters pack are unique, default case.
Definition: traits.h:47
Check if a template T is in Template pack Ts.
Definition: traits.h:77
is_included Default case
Definition: traits.h:98
Test correctness of type given to a memory manager.
Definition: traits.h:59
Check if a tuple of types T1 is included in a tuple of type T2, all type in T1 are in T2...
Definition: traits.h:115
STL namespace.
constexpr bool Contains_v
Direct Contains value accessor.
Definition: traits.h:91
constexpr bool is_included_v
Value accessor to test if the types of tuple T1 are in types of tuple T2.
Definition: traits.h:121
constexpr auto type_name()
Create a std::string_view containing a full type name of T.
Definition: traits.h:127
constexpr bool is_managed_memory_v
Direct IsManagedMemory value accessor.
Definition: traits.h:70