xtd 0.2.0
Loading...
Searching...
No Matches
lesser.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 {
38 template<class value_t = void>
39 struct lesser {
41
44 using first_argument_type = value_t;
46 using second_argument_type = value_t;
48 using result_type = bool;
50
52
55 lesser() = default;
60
62
68 constexpr auto operator()(const first_argument_type& x, const second_argument_type& y) const -> result_type {
69 if (&x == &y) return false;
70 if (comparer_) return comparer_->compare(x, y) < 0;
71 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) < 0;
72 else if constexpr(xtd::helpers::less_than_comparable<first_argument_type>) return std::less<first_argument_type> {}(x, y);
73 else return std::less<const void*> {}(static_cast<const void*>(&x), static_cast<const void*>(&y));
74 }
75
76
77 private:
78 const xtd::collections::generic::icomparer<value_t>* comparer_ = nullptr;
79 };
80 }
81 }
82 }
83}
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 less than comparable.
Definition less_than_comparable.hpp:28
Contains xtd::collections::generic::icomparer <type_t> interface.
@ 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.
Contains xtd::helpers::less_than_comparable concept.
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
Implements a function object for compare data.
Definition comparer.hpp:32
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 the other.
Definition lesser.hpp:68
value_t first_argument_type
Represents the first argument type.
Definition lesser.hpp:44
lesser()=default
Initializes a new instance of the comparer.
lesser(const xtd::collections::generic::icomparer< value_t > &comparer)
Initializes a new instance of the comparer with specified comparer.
Definition lesser.hpp:58
value_t second_argument_type
Represents the second argument type.
Definition lesser.hpp:46
bool result_type
Represents the result type.
Definition lesser.hpp:48