acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
cmp.h
1
#pragma once
2
3
4
template
<
class
TYPE>
5
struct
add_const
6
{
7
typedef
const
TYPE type;
8
};
9
10
11
template
<
class
TYPE>
12
struct
add_volatile
13
{
14
typedef
volatile
TYPE type;
15
};
16
17
template
<
class
TYPE>
18
struct
add_cv
19
{
20
typedef
const
volatile
TYPE type;
21
};
22
23
24
template
<
class
TYPE>
25
struct
add_reference
26
{
27
typedef
TYPE& type;
28
};
29
30
template
<
class
TYPE>
31
struct
add_lvalue_reference
32
{
33
typedef
typename
add_reference<TYPE>::typetype
;
34
};
35
36
37
template
<
class
TYPE>
38
struct
add_rvalue_reference
39
{
40
// add rvalue matter
41
typedef
TYPE&& type;
42
};
43
44
45
46
// CLASS _Unrefwrap
47
template
<
class
TYPE>
48
class
reference_wrapper
;
49
50
51
52
53
template
<
typename
TYPE >
54
void
__swap(TYPE & t1,TYPE & t2)
55
{
56
57
TYPE t = t1;
58
59
t1 = t2;
60
61
t2 = t;
62
63
}
64
//
65
//
66
//template<class... TYPES>
67
//class tuple;
68
//
69
//template<>
70
//class tuple<>
71
//{
72
//public:
73
// typedef tuple<> TUPLE_TYPE;
74
//
75
// tuple()
76
// {
77
// }
78
//
79
// tuple(const tuple&) noexcept
80
// {
81
// }
82
//
83
// void swap(TUPLE_TYPE&) noexcept
84
// {
85
// }
86
//
87
// bool equals(const TUPLE_TYPE&) noexcept
88
// {
89
// return true;
90
// }
91
//
92
// bool less(const TUPLE_TYPE&)noexcept
93
// {
94
// return false;
95
// }
96
//
97
//
98
//
99
// template< class... TYPES2>
100
// inline bool operator==(const tuple<TYPES2...>& right)
101
// {
102
// return equals(right);
103
// }
104
//
105
// template< class... TYPES2>
106
// inline bool operator!=( const tuple<TYPES2...>& right)
107
// {
108
// return !(*this == right);
109
// }
110
//
111
// template< class... TYPES2>
112
// inline bool operator<( const tuple<TYPES2...>& right)
113
// {
114
// return less(right);
115
// }
116
//
117
// template< class... TYPES2>
118
// inline bool operator>=( const tuple<TYPES2...>& right)
119
// {
120
// return !(less(right));
121
// }
122
//
123
// template< class... TYPES2>
124
// inline bool operator>( const tuple<TYPES2...>& right)
125
// {
126
// return right.less(*this);
127
// }
128
//
129
// template< class... TYPES2>
130
// inline bool operator<=(const tuple<TYPES2...>& right)
131
// {
132
// return !(right.less(*this));
133
// }
134
//
135
//};
136
//
137
//
138
//
139
//template<class TYPE,
140
// class... REST>
141
//class tuple<TYPE,REST...>
142
// : public tuple<REST...>
143
//{
144
//public:
145
// typedef TYPE THIS_TYPE;
146
// typedef tuple<TYPE,REST...> TUPLE_TYPE;
147
// typedef tuple<REST...> BASE_TYPE;
148
// static const size_t TYPE_SIZE = 1 + sizeof...(REST);
149
//
150
// TYPE m_val;
151
//
152
//
153
// tuple()
154
// {
155
// }
156
//
157
// template < class... OTHER >
158
// tuple(const tuple<OTHER...>& right)
159
// : BASE_TYPE(right.get_rest()),m_val(right.m_val)
160
// {
161
// }
162
//
163
// template < class... OTHER >
164
// tuple(tuple<OTHER...>&& right)
165
// : BASE_TYPE(::transfer(right.get_rest())),m_val(::transfer(right.m_val))
166
// {
167
// }
168
//
169
// explicit tuple(const TYPE& val,const REST&... rest)
170
// : BASE_TYPE(rest...),
171
// m_val(val)
172
// {
173
// }
174
//
175
// explicit tuple(TYPE && val,const REST &&... rest)
176
// : BASE_TYPE(::transfer(rest...)),m_val(::transfer(val))
177
// {
178
// }
179
//
180
//
181
// template<class... OTHER>
182
// TUPLE_TYPE& operator=(const tuple<OTHER...>& right)
183
// {
184
// m_val = right.m_val;
185
// (BASE_TYPE&)*this = right.get_rest();
186
// return (*this);
187
// }
188
//
189
// template<class... OTHER>
190
// TUPLE_TYPE& operator=(tuple<OTHER...>&& right)
191
// {
192
// m_val = ::transfer(right.m_val);
193
// BASE_TYPE::operator = (::transfer(right.get_rest()));
194
// return *this;
195
// }
196
//
197
// template<class... OTHER>
198
// bool equals(const tuple<OTHER...>& right) const
199
// {
200
// return m_val == right.m_val && BASE_TYPE::equals(right.get_rest());
201
// }
202
//
203
// template<class... OTHER>
204
// bool less(const tuple<OTHER...>& right) const
205
// {
206
// return m_val < right.m_val || (!(right.m_val < m_val) && BASE_TYPE::less(right.get_rest()));
207
// }
208
//
209
// template < class TYPE1, class TYPE2>
210
// tuple(const pair < TYPE1, TYPE2 > & right) :
211
// BASE_TYPE( tuple < TYPE2 > ( right.element2() ) ),
212
// m_val(right.element1())
213
// {
214
//
215
// }
216
//
217
//
218
// TUPLE_TYPE & operator=(const TUPLE_TYPE & right)
219
// {
220
//
221
// m_val = right.m_val;
222
//
223
// BASE_TYPE::operator =(right.get_rest());
224
//
225
// return *this;
226
//
227
// }
228
//
229
//
230
// template < class TYPE1, class TYPE2>
231
// TUPLE_TYPE & operator=(const pair < TYPE1, TYPE2 >& right)
232
// {
233
//
234
// m_val = right.first;
235
//
236
// BASE_TYPE::operator =(tuple<TYPE2>(right.element2()));
237
//
238
// return *this;
239
//
240
// }
241
//
242
//
243
// template < class TYPE1, class TYPE2 >
244
// tuple(pair < TYPE1, TYPE2 > && right) :
245
// BASE_TYPE(tuple<TYPE2>(::transfer(right.second))),
246
// m_val(::transfer(right.first))
247
// {
248
//
249
// }
250
//
251
//
252
// TUPLE_TYPE & operator=(TUPLE_TYPE&& right)
253
// {
254
//
255
// m_val = ::transfer(right.m_val);
256
//
257
// BASE_TYPE::operator = (::transfer(right.get_rest()));
258
//
259
// return (*this);
260
//
261
// }
262
//
263
//
264
// template < class TYPE1, class TYPE2>
265
// TUPLE_TYPE& operator=(pair<TYPE1,TYPE2>&& right)
266
// {
267
//
268
// m_val = ::transfer(right.element1());
269
//
270
// BASE_TYPE::operator = (tuple<TYPE2>(::transfer(right.second)));
271
//
272
// return *this;
273
//
274
// }
275
//
276
//
277
// BASE_TYPE & get_rest()
278
// {
279
//
280
// return *this;
281
//
282
// }
283
//
284
// const BASE_TYPE & get_rest() const
285
// {
286
//
287
// return *this;
288
//
289
// }
290
//
291
//
292
// void swap(tuple& right)
293
// {
294
//
295
// swap(m_val,right.m_val);
296
//
297
// BASE_TYPE::swap((BASE_TYPE&)right);
298
//
299
// }
300
//
301
//};
302
//
303
//template<class... TYPES>
304
//inline void swap(tuple<TYPES...>& left, tuple<TYPES...>& right)
305
//{
306
// return left.swap(right);
307
//}
308
//
309
//
310
//template<size_t m_iIndex, class TUPLE>
311
//struct tuple_element;
312
//
313
//template<class TYPE1, class... REST1>
314
//struct tuple_element<0,tuple<TYPE1,REST1...> >
315
//{
316
// typedef TYPE1 type;
317
// typedef typename add_lvalue_reference<const TYPE1>::type_Ctype;
318
// typedef typename add_lvalue_reference<TYPE1>::type_Rtype;
319
// //typedef typename add_rvalue_reference<TYPE1>::type_RRtype;
320
// typedef tuple<TYPE1,REST1...> TUPLE_TYPE;
321
//};
322
//
323
//template<size_t m_iIndex, class TYPE1, class... REST1>
324
//struct tuple_element<m_iIndex,tuple<TYPE1,REST1...> >
325
// : public tuple_element<m_iIndex - 1,tuple<REST1...> >
326
//{
327
//};
328
//
329
//
330
//template<size_t m_iIndex, class TUPLE>
331
//struct tuple_element<m_iIndex,const TUPLE>
332
// : public tuple_element<m_iIndex,TUPLE>
333
//{
334
// typedef tuple_element<m_iIndex,TUPLE> BASE_TYPE;
335
// typedef typename add_const<typename BASE_TYPE::platform::type>::typetype;
336
//};
337
//
338
//template<size_t m_iIndex, class TUPLE>
339
//struct tuple_element<m_iIndex,volatile TUPLE>
340
// : public tuple_element<m_iIndex,TUPLE>
341
//{
342
// typedef tuple_element<m_iIndex,TUPLE> BASE_TYPE;
343
// typedef typename add_volatile<typename BASE_TYPE::platform::type>::typetype;
344
//};
345
//
346
//template<size_t m_iIndex,
347
// class TUPLE>
348
//struct tuple_element<m_iIndex,const volatile TUPLE>
349
// : public tuple_element<m_iIndex,TUPLE>
350
//{
351
// typedef tuple_element<m_iIndex,TUPLE> BASE_TYPE;
352
// typedef typename add_cv<typename BASE_TYPE::platform::type>::typetype;
353
//};
354
//
355
//
356
//template<size_t m_iIndex, class... TYPES>
357
//inline typename tuple_element<m_iIndex,tuple<TYPES...> >::_Rtype get(tuple<TYPES...>& TUPLE)
358
//{
359
// typedef typename tuple_element<m_iIndex,tuple<TYPES...> >::TUPLE_TYPE TUPLE_TYPE;
360
// return (((TUPLE_TYPE&)TUPLE).m_val);
361
//}
362
//
363
//template<size_t m_iIndex, class... TYPES>
364
//inline typename tuple_element<m_iIndex,tuple<TYPES...> >::_Ctype get(const tuple<TYPES...>& TUPLE)
365
//{
366
// typedef typename tuple_element<m_iIndex,tuple<TYPES...> >::TUPLE_TYPE TUPLE_TYPE;
367
// return (((TUPLE_TYPE&)TUPLE).m_val);
368
//}
369
//
370
//
371
//template<size_t m_iIndex, class... TYPES>
372
//inline typename tuple_element<m_iIndex,tuple<TYPES...> >::_RRtype get(tuple<TYPES...>&& TUPLE)
373
//{
374
//
375
// typedef typename tuple_element<m_iIndex,tuple<TYPES...> >::TUPLE_TYPE TUPLE_TYPE;
376
// //typedef typename tuple_element<m_iIndex,tuple<TYPES...> >::_RRtype _RRtype;
377
// return (::transfer(((TUPLE_TYPE&)TUPLE).m_val));
378
//
379
//}
380
//
381
//
382
//template<class... TYPES> inline
383
//tuple < TYPES&&... > make_tuple(TYPES&&... args)
384
//{
385
//
386
// return ::transfer(args...);
387
//
388
//}
389
//
390
//
391
//template<class... TYPES> inline
392
//tuple<TYPES&...>
393
//tie(TYPES&... args) noexcept
394
//{
395
//
396
// typedef tuple<TYPES&...> TUPLE_TYPE;
397
//
398
// return (TUPLE_TYPE(args...));
399
//
400
//}
401
402
403
404
405
406
407
408
409
410
411
412
413
template
<
typename
TYPE1,
typename
TYPE2 >
414
inline ::i32 cmp(
const
TYPE1 & t1,
const
TYPE2 & t2)
415
{
416
return
(t1 < t2) ? -1 : (t1 < t2) ? 1 : 0;
417
}
418
419
420
template
<
typename
TYPE1,
typename
TYPE2 >
421
inline ::i32 icmp(
const
TYPE1 & t1,
const
TYPE2 & t2)
422
{
423
return
cmp(t1, t2);
424
}
425
426
template
< >
427
inline ::i32 cmp(const ::scoped_string & scopedstr1, const ::scoped_string & scopedstr2)
428
{
429
return
str1.compare(str2);
430
}
431
432
433
template
< >
434
inline ::i32 icmp(const ::scoped_string & scopedstr1,const ::scoped_string & scopedstr2)
435
{
436
return
str1.case_insensitive_order(str2);
437
}
438
439
template
<
size_t
TUPLE_SIZE>
struct
cmp_tuple
440
{
441
template
<
typename
T1,
typename
T2>
442
::i32 operator()(
const
T1 & t1,
const
T2 & t2)
const
443
{
444
::i32 r =
cmp_tuple
<TUPLE_SIZE - 1>()(t1,t2);
445
return
(r != 0) ? r : cmp(get<TUPLE_SIZE - 1>(t1),get<TUPLE_SIZE - 1>(t2));
446
}
447
};
448
449
450
template
<
size_t
TUPLE_SIZE>
struct
icmp_tuple
451
{
452
template
<
typename
T1,
typename
T2>
453
::i32 operator()(
const
T1 & t1,
const
T2 & t2)
const
454
{
455
::i32 r =
icmp_tuple
<TUPLE_SIZE - 1>()(t1,t2);
456
return
(r != 0) ? r : icmp(get<TUPLE_SIZE - 1>(t1),get<TUPLE_SIZE - 1>(t2));
457
}
458
};
459
460
template
<>
struct
cmp_tuple
<0>
461
{
462
template
<
typename
T1,
typename
T2>
463
::i32 operator()(
const
T1&,
const
T2&)
const
464
{
465
return
0;
466
}
467
};
468
469
template
<>
struct
icmp_tuple
<0>
470
{
471
template
<
typename
T1,
typename
T2>
472
::i32 operator()(
const
T1&,
const
T2&)
const
473
{
474
return
0;
475
}
476
};
477
478
479
480
481
482
483
template
< >
484
inline ::i32 cmp(const ::i32 & i1,const ::i32 & i2)
485
{
486
return
i1 - i2;
487
}
488
489
490
template
< >
491
inline ::i32 cmp(const ::i16 & sh1,const ::i16 & sh2)
492
{
493
return
sh1 - sh2;
494
}
495
496
497
template
< >
498
inline ::i32 cmp(const ::i8 & ch1,const ::i8 & ch2)
499
{
500
return
ch1 - ch2;
501
}
502
503
template
< >
504
inline ::i32 cmp(const ::u32 & i1,const ::u32 & i2)
505
{
506
return
i1 - i2;
507
}
508
509
template
< >
510
inline ::i32 cmp(const ::u16 & sh1,const ::i16 & sh2)
511
{
512
return
sh1 - sh2;
513
}
514
515
516
template
< >
517
inline ::i32 cmp(const ::u8 & ch1,const ::u8 & ch2)
518
{
519
return
ch1 - ch2;
520
}
521
522
523
template
< >
524
inline ::i32 cmp(const ::f64 & d1,const ::f64 & d2)
525
{
526
return ::acme::sgn(d1 - d2);
527
}
528
529
530
template
< >
531
inline ::i32 cmp(const ::f32 & f1,const ::f32 & f2)
532
{
533
return ::acme::sgn(f1 - f2);
534
}
535
536
537
538
template
< >
539
inline ::i32 cmp(const ::i32 & t1,const ::u32 & t2)
540
{
541
return
(t1 < 0) ? -1 : ((::u32) t1 < t2) ? 1 : 0;
542
}
reference_wrapper
Definition
cmp.h:48
add_const
Definition
cmp.h:6
add_cv
Definition
cmp.h:19
add_lvalue_reference
Definition
cmp.h:32
add_reference
Definition
cmp.h:26
add_rvalue_reference
Definition
cmp.h:39
add_volatile
Definition
cmp.h:13
cmp_tuple
Definition
cmp.h:440
icmp_tuple
Definition
cmp.h:451
platform
cmp.h
Generated by
1.17.0