YSTest: type_op.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

type_op.hpp
浏览该文件的文档.
1 /*
2 © 2011-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
31 #ifndef YB_INC_ystdex_type_op_hpp_
32 #define YB_INC_ystdex_type_op_hpp_ 1
33
34 #include "tuple.hpp" // for is_class, std::declval, is_detected, vseq::apply,
35 // _t, bool_constant, is_void, is_same, remove_reference_t, and_, cond_t,
36 // is_enum, vdefer, underlying_type_t, common_type_t;
37
38 namespace ystdex
39 {
40
41 namespace details
42 {
43
45 template<typename _type, typename _type2>
46 using subscription_t
47 = decltype(std::declval<_type>()[std::declval<_type2>()]);
48
50 template<typename _type, typename _type2>
51 using equality_operator_t
52 = decltype(std::declval<_type>() == std::declval<_type2>());
53
54
56
57 template<class _type>
59 struct has_nonempty_virtual_base
60 {
61 static_assert(is_class<_type>(),
62 "Non-class type found @ ystdex::has_nonempty_virtual_base;");
63
64 private:
65 struct A : _type
66 {};
67
68 struct B : _type
69 {};
70
71 struct C : A, B
72 {};
73
74 public:
75 static yconstexpr const bool value = sizeof(C) < sizeof(A) + sizeof(B);
76 };
77
78
80 template<class _type1, class _type2>
81 struct have_common_nonempty_virtual_base
82 {
83 static_assert(and_<is_class<_type1>, is_class<_type2>>(),
84 "Non-class type found @ ystdex::has_common_nonempty_virtual_base;");
85
86 private:
87 struct A : virtual _type1
88 {};
89
90 struct B : virtual _type2
91 {};
92
93 #ifdef YB_IMPL_GNUCPP
94 # if YB_IMPL_GNUCPP >= 40600
95 # pragma GCC diagnostic push
96 # pragma GCC diagnostic ignored "-Wextra"
97 # else
98 # pragma GCC system_header
99 # endif
100 #endif
101
102 struct C : A, B
103 {};
104
105 #if YB_IMPL_GNUCPP && YB_IMPL_GNUCPP >= 40600
106 //# pragma GCC diagnostic warning "-Wextra"
107 # pragma GCC diagnostic pop
108 #endif
109
110 public:
111 static yconstexpr const bool value = sizeof(C) < sizeof(A) + sizeof(B);
112 };
114
116 template<typename _type>
117 using mem_value_t = decltype(std::declval<_type>().value);
118
120 template<typename _type>
121 using mem_value_type_t = typename _type::value_type;
122
123
125
126 template<typename _type>
127 struct member_target_type_impl
128 {
129 using type = void;
130 };
131
132 template<class _tClass, typename _type>
133 struct member_target_type_impl<_type _tClass::*>
134 {
135 using type = _tClass;
136 };
138
139 } // namespace details;
140
141
143
144
148 template<class _type, typename... _tParams>
149 struct has_mem_apply : is_detected<vseq::apply, _type, _tParams...>
150 {};
151
152
157 template<class _type>
158 struct has_mem_type : is_detected<_t, _type>
159 {};
160
161
166 template<class _type>
167 struct has_mem_value : is_detected<details::mem_value_t, _type>
168 {};
169
170
175 template<class _type>
176 struct has_mem_value_type : is_detected<details::mem_value_type_t, _type>
177 {};
179
180
182
183
187 template<typename _type1, typename _type2>
188 struct has_subscription
189 : bool_constant<is_detected<details::subscription_t, _type1, _type2>::value
190 && !is_void<detected_t<details::subscription_t, _type1, _type2>>::value>
191 {};
192
193
198 template<typename _type, typename _type2 = _type>
199 struct has_equality_operator : is_detected_convertible<bool,
200 details::equality_operator_t, _type, _type2>
201 {};
202
203
208 template<class _type>
209 struct has_nonempty_virtual_base
210 : bool_constant<details::has_nonempty_virtual_base<_type>::value>
211 {};
213
214
220 template<class _type1, class _type2>
221 struct have_common_nonempty_virtual_base
222 : bool_constant<!is_same<_type1, _type2>::value
223 && details::have_common_nonempty_virtual_base<_type1, _type2>::value>
224 {};
225
226
228
229
235 template<typename _type>
236 struct remove_rcv : remove_cv<remove_reference_t<_type>>
237 {};
238
240 template<typename _type>
241 using remove_rcv_t = _t<remove_rcv<_type>>;
243
244
250 template<typename _type>
251 struct remove_rp : remove_pointer<remove_reference_t<_type>>
252 {};
253
254
259 template<typename _type>
260 struct remove_rpcv : remove_cv<_t<remove_rp<_type>>>
261 {};
262
263
268 template<typename _type>
269 using member_target_type_t = _t<details::member_target_type_impl<_type>>;
271
272
274
275
280 template<typename _type>
281 using underlying_cond_type_t
282 = cond_t<is_enum<_type>, vdefer<underlying_type_t, _type>, _type>;
283
288 template<typename _type, typename... _types>
289 using common_nonvoid_t = _t<cond_t<is_void<_type>,
290 vdefer<common_type_t, _types...>, identity<_type>>>;
291
296 template<typename... _types>
297 using common_underlying_t = common_type_t<underlying_cond_type_t<_types>...>;
298
299
312 template<size_t _vN>
313 struct n_tag
314 {
315 using type = n_tag<_vN - 1>;
316 };
317
318 template<>
319 struct n_tag<0>
320 {
321 using type = void;
322 };
324
329 using first_tag = n_tag<0>;
330
335 using second_tag = n_tag<1>;
336
337 } // namespace ystdex;
338
339 #endif
340
ystdex::common_nonvoid_t
_t< cond_t< is_void< _type >, vdefer< common_type_t, _types... >, identity< _type >>> common_nonvoid_t
取公共非空类型：若第一参数为非空类型则为第一参数，否则从其余参数推断。
Definition: type_op.hpp:290
ystdex::has_subscription
判断是否存在合式的结果为非 void 类型的 [] 操作符接受指定类型的表达式。
Definition: type_op.hpp:188
ystdex::has_equality_operator
判断是否存在合式的结果可转换为 bool 类型的 == 操作符接受指定类型的表达式。
Definition: type_op.hpp:199
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
ystdex::has_mem_value_type
判断 _type 是否包含 value_type 类型成员。
Definition: type_op.hpp:176
ystdex::details::has_nonempty_virtual_base::A
Definition: type_op.hpp:65
ystdex::have_common_nonempty_virtual_base
判断指定的两个类类型是否不同且有公共非空虚基类。
Definition: type_op.hpp:221
ystdex::has_nonempty_virtual_base
判断指定类型是否有非空虚基类。
Definition: type_op.hpp:209
ystdex::is_detected
typename details::detector< nonesuch, void, _gOp, _tParams... >::value_t is_detected
Definition: type_traits.hpp:667
ystdex::details::has_nonempty_virtual_base::C
Definition: type_op.hpp:71
ystdex::has_mem_type
判断 _type 是否包含 type 类型成员。
Definition: type_op.hpp:158
ystdex::identity
恒等元函数。
Definition: type_traits.hpp:961
ystdex::details::member_target_type_impl
Definition: type_op.hpp:127
ystdex::details::mem_value_t
decltype(std::declval< _type >().value) mem_value_t
Definition: type_op.hpp:117
ystdex::bool_constant
integral_constant< bool, _b > bool_constant
bool 常量。
Definition: type_traits.hpp:382
ystdex::n_tag
自然数标记。
Definition: type_op.hpp:313
ystdex::remove_rp
移除指针和引用类型。
Definition: type_op.hpp:251
ystdex::common_underlying_t
common_type_t< underlying_cond_type_t< _types >... > common_underlying_t
取公共底层类型。
Definition: type_op.hpp:297
ystdex::details::have_common_nonempty_virtual_base::B
Definition: type_op.hpp:90
ystdex::underlying_cond_type_t
cond_t< is_enum< _type >, vdefer< underlying_type_t, _type >, _type > underlying_cond_type_t
取底层类型。
Definition: type_op.hpp:282
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: type_traits.hpp:96
ystdex::has_mem_value
判断 _type 是否包含 value 成员。
Definition: type_op.hpp:167
ystdex::has_mem_apply
判断 _type 是否包含可以指定参数应用得到类型的成员 apply 模板。
Definition: type_op.hpp:149
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::cond_t
conditional_t< _tCond::value, _tThen, _tElse > cond_t
条件判断。
Definition: type_traits.hpp:698
tuple.hpp
元组类型和操作。
ystdex::n_tag< 0 >
Definition: type_op.hpp:319
ystdex::details::equality_operator_t
decltype(std::declval< _type >()==std::declval< _type2 >()) equality_operator_t
Definition: type_op.hpp:52
ystdex::remove_rpcv
移除可能被 cv-qualifier 修饰的引用和指针类型。
Definition: type_op.hpp:260
ystdex::details::have_common_nonempty_virtual_base::C
Definition: type_op.hpp:102
ystdex::remove_rcv_t
_t< remove_rcv< _type >> remove_rcv_t
Definition: type_op.hpp:241
platform::KeyCodes::DS::B
Definition: Keys.h:216
ystdex::details::member_target_type_impl::type
void type
Definition: type_op.hpp:129
ystdex::n_tag< 0 >::type
void type
Definition: type_op.hpp:321
ystdex::is_detected_convertible
is_convertible< detected_t< _gOp, _tParams... >, _tTo > is_detected_convertible
Definition: type_traits.hpp:686
ystdex::remove_rcv
移除可能被 cv-qualifier 修饰的引用类型。
Definition: type_op.hpp:236
ystdex::cpp2014::common_type_t
typename common_type< _types... >::type common_type_t
Definition: type_traits.hpp:356
ystdex::details::has_nonempty_virtual_base::value
static const bool value
Definition: type_op.hpp:75
ystdex::member_target_type_t
_t< details::member_target_type_impl< _type >> member_target_type_t
取成员指针类型指向的类类型。
Definition: type_op.hpp:269
ystdex::details::subscription_t
decltype(std::declval< _type >()[std::declval< _type2 >()]) subscription_t
Definition: type_op.hpp:47
ystdex::details::have_common_nonempty_virtual_base::A
Definition: type_op.hpp:87
ystdex::details::has_nonempty_virtual_base::B
Definition: type_op.hpp:68
ystdex::and_
逻辑操作元函数。
Definition: type_traits.hpp:394
ystdex::details::mem_value_type_t
typename _type::value_type mem_value_type_t
Definition: type_op.hpp:121
ystdex::details::member_target_type_impl< _type _tClass::* >::type
_tClass type
Definition: type_op.hpp:135
ystdex::details::has_nonempty_virtual_base
Definition: type_op.hpp:59
ystdex::details::have_common_nonempty_virtual_base
Definition: type_op.hpp:81