acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
cmp.h
1#pragma once
2
3
4template<class TYPE>
6{
7 typedef const TYPE type;
8};
9
10
11template<class TYPE>
13{
14 typedef volatile TYPE type;
15};
16
17template<class TYPE>
18struct add_cv
19{
20 typedef const volatile TYPE type;
21};
22
23
24template<class TYPE>
26{
27 typedef TYPE& type;
28};
29
30template<class TYPE>
32{
33 typedef typename add_reference<TYPE>::typetype;
34};
35
36
37template<class TYPE>
39{
40 // add rvalue matter
41 typedef TYPE&& type;
42};
43
44
45
46// CLASS _Unrefwrap
47template<class TYPE>
49
50
51
52
53template < typename TYPE >
54void __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
413template < typename TYPE1, typename TYPE2 >
414inline ::i32 cmp(const TYPE1 & t1,const TYPE2 & t2)
415{
416 return (t1 < t2) ? -1 : (t1 < t2) ? 1 : 0;
417}
418
419
420template < typename TYPE1,typename TYPE2 >
421inline ::i32 icmp(const TYPE1 & t1,const TYPE2 & t2)
422{
423 return cmp(t1, t2);
424}
425
426template < >
427inline ::i32 cmp(const ::scoped_string & scopedstr1, const ::scoped_string & scopedstr2)
428{
429 return str1.compare(str2);
430}
431
432
433template < >
434inline ::i32 icmp(const ::scoped_string & scopedstr1,const ::scoped_string & scopedstr2)
435{
436 return str1.case_insensitive_order(str2);
437}
438
439template<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
450template<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
460template<> 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
469template<> 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
483template < >
484inline ::i32 cmp(const ::i32 & i1,const ::i32 & i2)
485{
486 return i1 - i2;
487}
488
489
490template < >
491inline ::i32 cmp(const ::i16 & sh1,const ::i16 & sh2)
492{
493 return sh1 - sh2;
494}
495
496
497template < >
498inline ::i32 cmp(const ::i8 & ch1,const ::i8 & ch2)
499{
500 return ch1 - ch2;
501}
502
503template < >
504inline ::i32 cmp(const ::u32 & i1,const ::u32 & i2)
505{
506 return i1 - i2;
507}
508
509template < >
510inline ::i32 cmp(const ::u16 & sh1,const ::i16 & sh2)
511{
512 return sh1 - sh2;
513}
514
515
516template < >
517inline ::i32 cmp(const ::u8 & ch1,const ::u8 & ch2)
518{
519 return ch1 - ch2;
520}
521
522
523template < >
524inline ::i32 cmp(const ::f64 & d1,const ::f64 & d2)
525{
526 return ::acme::sgn(d1 - d2);
527}
528
529
530template < >
531inline ::i32 cmp(const ::f32 & f1,const ::f32 & f2)
532{
533 return ::acme::sgn(f1 - f2);
534}
535
536
537
538template < >
539inline ::i32 cmp(const ::i32 & t1,const ::u32 & t2)
540{
541 return (t1 < 0) ? -1 : ((::u32) t1 < t2) ? 1 : 0;
542}
Definition cmp.h:48
Definition cmp.h:6
Definition cmp.h:19
Definition cmp.h:32
Definition cmp.h:26
Definition cmp.h:39
Definition cmp.h:13
Definition cmp.h:440
Definition cmp.h:451