xtd 0.2.0
__polymorphic_comparer.hpp
Go to the documentation of this file.
1
4
5#pragma once
7#if !defined(__XTD_CORE_INTERNAL__)
8#error "Do not include this file: Internal use only"
9#endif
11
12#include "../icomparable.hpp"
13#include "../int32.hpp"
14#include <functional>
15#include <type_traits>
16
18
19template<typename type_t, typename bool_t>
20struct __icomparable_comparer__ {};
21
22template<typename type_t>
23struct __icomparable_comparer__<type_t, std::true_type> {
24 xtd::int32 operator()(const type_t& x, const type_t& y) const {return static_cast<const xtd::icomparable<type_t>&>(x).compare_to(y);}
25};
26
27template<typename type_t>
28struct __icomparable_comparer__<type_t, std::false_type> {
29 xtd::int32 operator()(const type_t& x, const type_t& y) const {return x < y ? -1 : (x > y ? 1 : 0);}
30};
31
32template<class type_t, class bool_t>
33struct __polymorphic_comparer__ {};
34
35template<class type_t>
36struct __polymorphic_comparer__<type_t, std::true_type> {
37 xtd::int32 operator()(const type_t& x, const type_t& y) const {return __icomparable_comparer__<type_t, typename std::is_base_of<xtd::icomparable<type_t>, type_t>::type> {}(x, y);}
38};
39
40template<class type_t>
41struct __polymorphic_comparer__<type_t, std::false_type> {
42 xtd::int32 operator()(const type_t& x, const type_t& y) const {return x < y ? -1 : (x > y ? 1 : 0);}
43};
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:21
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
@ y
The Y key.
@ x
The X key.