xtd 0.2.0
Loading...
Searching...
No Matches
comparer.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../icomparer.hpp"
7#include "../../../int32.hpp"
9
11namespace xtd {
13 namespace collections {
15 namespace generic {
17 namespace helpers {
31 template<class value_t = void>
32 struct comparer {
34
37 using first_argument_type = value_t;
39 using second_argument_type = value_t;
43
45
48 comparer() = default;
53
55
67 constexpr auto operator()(const first_argument_type& x, const second_argument_type& y) const -> result_type {
68 if (&x == &y) return 0;
69 if (comparer_) return comparer_->compare(x, y);
70 if constexpr(std::is_polymorphic_v<first_argument_type> && std::is_base_of_v<xtd::icomparable<first_argument_type>, first_argument_type>) return static_cast<const xtd::icomparable<first_argument_type>&>(x).compare_to(y);
71 else if constexpr(xtd::helpers::strictly_ordered<first_argument_type>) return x < y ? -1 : (x > y ? 1 : 0);
72 else return &x < &y ? -1 : 1;
73 }
74
75
76 private:
77 const xtd::collections::generic::icomparer<value_t>* comparer_ = nullptr;
78 };
79 }
80 }
81 }
82}
Exposes a method that compares two objects.
Definition icomparer.hpp:30
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:22
virtual int32 compare_to(const type_t &obj) const noexcept=0
Compares the current instance with another object of the same type.
Concept strictly ordered.
Definition strictly_ordered.hpp:28
Contains xtd::collections::generic::icomparer <type_t> interface.
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
@ y
The Y key.
Definition console_key.hpp:136
@ x
The X key.
Definition console_key.hpp:134
Contains xtd::icomparable interface.
Contains xtd::int32 type.
The xtd::collections::generic::helpers namespace contains helpers for generic collections,...
Definition allocator.hpp:14
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::helpers::strictly_ordered concept.
comparer(const xtd::collections::generic::icomparer< value_t > &comparer)
Initializes a new instance of the comparer with specified comparer.
Definition comparer.hpp:51
comparer()=default
Initializes a new instance of the comparer.
xtd::int32 result_type
Represents the result type.
Definition comparer.hpp:41
value_t second_argument_type
Represents the second argument type.
Definition comparer.hpp:39
constexpr auto operator()(const first_argument_type &x, const second_argument_type &y) const -> result_type
Compares two entities and returns a value indicating whether one is less than, equal to,...
Definition comparer.hpp:67
value_t first_argument_type
Represents the first argument type.
Definition comparer.hpp:37