KTL
meta.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <type_traits>
4 
5 namespace ktl::detail
6 {
7  // has value_type
8  template<typename Alloc, typename = void>
9  struct has_no_value_type : std::true_type {};
10 
11  template<typename Alloc>
12  struct has_no_value_type<Alloc, std::void_t<typename Alloc::value_type>> : std::false_type {};
13 
14  template<typename Alloc>
16 
17  // get size_type
18  template<typename Alloc, typename = void>
20  {
21  using type = size_t;
22  };
23 
24  template<typename Alloc>
25  struct get_size_type<Alloc, std::void_t<typename Alloc::size_type>>
26  {
27  using type = typename Alloc::size_type;
28  };
29 
30  template<typename Alloc>
32 
33  // has construct(T*, Args&&...)
34  template<typename Void, typename... Types>
35  struct has_construct : std::false_type {};
36 
37  template<typename Alloc, typename... Args>
38  struct has_construct<std::void_t<decltype(std::declval<Alloc&>().construct(std::declval<Args>()...))>, Alloc, Args...> : std::true_type {};
39 
40  template<typename Alloc, typename... Args>
41  constexpr bool has_construct_v = has_construct<void, Alloc, Args...>::value;
42 
43  // has destroy(T*)
44  template<typename Alloc, typename Ptr, typename = void>
45  struct has_destroy : std::false_type {};
46 
47  template<typename Alloc, typename Ptr>
48  struct has_destroy<Alloc, Ptr, std::void_t<decltype(std::declval<Alloc&>().destroy(std::declval<Ptr>()))>> : std::true_type {};
49 
50  template<typename Alloc, typename Ptr>
52 
53  // has max_size()
54  template<typename Alloc, typename = void>
55  struct has_max_size : std::false_type {};
56 
57  template<typename Alloc>
58  struct has_max_size<Alloc, std::void_t<decltype(std::declval<Alloc&>().max_size())>> : std::true_type {};
59 
60  template<typename Alloc>
62 
63  // has owns(void*)
64  template<typename Alloc, typename = void>
65  struct has_owns : std::false_type {};
66 
67  template<typename Alloc>
68  struct has_owns<Alloc, std::void_t<decltype(std::declval<Alloc&>().owns(std::declval<void*>()))>> : std::true_type {};
69 
70  template<typename Alloc>
72 
73 
74 
75  // has allocate(size_t) noexcept
76  template<typename Alloc>
77  constexpr bool has_nothrow_allocate_v = noexcept(std::declval<Alloc&>().allocate(std::declval<size_t>()));
78 
79  // has deallocate(void*, size_t) noexcept
80  template<typename Alloc>
81  constexpr bool has_nothrow_deallocate_v = noexcept(std::declval<Alloc&>().deallocate(std::declval<void*>(), std::declval<size_t>()));
82 
83  // has T& == T& noexcept
84  template<typename T>
85  constexpr bool has_nothrow_equal_v = noexcept(std::declval<T&>() == std::declval<T&>());
86 
87  // has T& == T& noexcept
88  template<typename T>
89  constexpr bool has_nothrow_not_equal_v = noexcept(std::declval<T&>() == std::declval<T&>());
90 
91  // has construct(T*, Args&&...) noexcept
92  template<typename Void, typename... Types>
93  struct has_nothrow_construct : std::false_type {};
94 
95  template<typename Alloc, typename... Args>
96  struct has_nothrow_construct<std::enable_if_t<has_construct_v<Alloc, Args...>>, Alloc, Args...>
97  : std::bool_constant<noexcept(std::declval<Alloc&>().construct(std::declval<Args>()...))> {};
98 
99  template<typename Alloc, typename... Args>
100  constexpr bool has_nothrow_construct_v = has_nothrow_construct<void, Alloc, Args...>::value;
101 
102  // has destroy(T*) noexcept
103  template<typename Alloc, typename Ptr, typename = void>
104  struct has_nothrow_destroy : std::false_type {};
105 
106  template<typename Alloc, typename Ptr>
107  struct has_nothrow_destroy<Alloc, Ptr, std::enable_if_t<has_destroy_v<Alloc, Ptr>>>
108  : std::bool_constant<noexcept(std::declval<Alloc&>().destroy(std::declval<Ptr>()))> {};
109 
110  template<typename Alloc, typename Ptr>
112 
113  // has max_size() noexcept
114  template<typename Alloc, typename = void>
115  struct has_nothrow_max_size : std::false_type {};
116 
117  template<typename Alloc>
118  struct has_nothrow_max_size<Alloc, std::enable_if_t<has_max_size_v<Alloc>>>
119  : std::bool_constant<noexcept(std::declval<Alloc&>().max_size())> {};
120 
121  template<typename Alloc>
123 
124  // has owns(void*) noexcept
125  template<typename Alloc, typename = void>
126  struct has_nothrow_owns : std::false_type {};
127 
128  template<typename Alloc>
129  struct has_nothrow_owns<Alloc, std::enable_if_t<has_owns_v<Alloc>>>
130  : std::bool_constant<noexcept(std::declval<Alloc&>().owns(std::declval<void*>()))> {};
131 
132  template<typename Alloc>
134 }
Definition: fallback_fwd.h:23
constexpr bool has_nothrow_construct_v
Definition: meta.h:100
constexpr bool has_max_size_v
Definition: meta.h:61
constexpr bool has_construct_v
Definition: meta.h:41
constexpr bool has_nothrow_destroy_v
Definition: meta.h:111
constexpr bool has_no_value_type_v
Definition: meta.h:15
constexpr bool has_nothrow_equal_v
Definition: meta.h:85
constexpr bool has_nothrow_deallocate_v
Definition: meta.h:81
typename get_size_type< Alloc, void >::type get_size_type_t
Definition: meta.h:31
constexpr bool has_destroy_v
Definition: meta.h:51
constexpr bool has_nothrow_allocate_v
Definition: meta.h:77
constexpr bool has_owns_v
Definition: meta.h:71
constexpr bool has_nothrow_not_equal_v
Definition: meta.h:89
constexpr bool has_nothrow_owns_v
Definition: meta.h:133
constexpr bool has_nothrow_max_size_v
Definition: meta.h:122
Definition: meta.h:20
size_t type
Definition: meta.h:21
Definition: meta.h:35
Definition: meta.h:45
Definition: meta.h:55
Definition: meta.h:9
Definition: meta.h:104
Definition: meta.h:115
Definition: meta.h:126
Definition: meta.h:65