xtd 0.2.0
Loading...
Searching...
No Matches
comparison_operators.hpp
Go to the documentation of this file.
1
4#pragma once
5#define __XTD_STD_INTERNAL__
6#include "../internal/__xtd_std_version.hpp"
7#undef __XTD_STD_INTERNAL__
8
10namespace xtd {
12 namespace extensions {
29 template<typename type_t, typename comparable_t>
31 public:
33
39 friend bool operator <(const type_t& lhs, const type_t& rhs) noexcept {
40 auto rhs_ptr = &rhs;
41 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) < 0;
42 }
43
48 friend bool operator <=(const type_t& lhs, const type_t& rhs) noexcept {
49 auto rhs_ptr = &rhs;
50 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) <= 0;
51 }
52
57 friend bool operator >(const type_t& lhs, const type_t& rhs) noexcept {
58 auto rhs_ptr = &rhs;
59 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) > 0;
60 }
61
66 friend bool operator >=(const type_t& lhs, const type_t& rhs) noexcept {
67 auto rhs_ptr = &rhs;
68 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) >= 0;
69 }
70
71#if defined(__xtd__cpp_lib_three_way_comparison)
79 friend std::strong_ordering operator <=>(const type_t& lhs, const type_t& rhs) noexcept {
80 auto rhs_ptr = &rhs;
81 if (dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) < 0) return std::strong_ordering::less;
82 if (dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) > 0) return std::strong_ordering::greater;
83 if (dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) == 0) return std::strong_ordering::equivalent;
84 return std::strong_ordering::less;
85 }
86#endif
88 private:
89 friend comparable_t;
90 comparison_operators() = default;
91 };
92 }
93}
Internal comparable operators definition.
Definition comparison_operators.hpp:30
friend std::strong_ordering operator<=>(const type_t &lhs, const type_t &rhs) noexcept
Three-way comparison operator with specidied lhs ans rhs values.
Definition comparison_operators.hpp:79
friend bool operator<(const type_t &lhs, const type_t &rhs) noexcept
Less than comparison operator with specidied lhs ans rhs values.
Definition comparison_operators.hpp:39
friend bool operator>=(const type_t &lhs, const type_t &rhs) noexcept
Less than comparison operator with specidied lhs ans rhs values.
Definition comparison_operators.hpp:66
friend bool operator<=(const type_t &lhs, const type_t &rhs) noexcept
Less than or equal to comparison operator with specidied lhs ans rhs values.
Definition comparison_operators.hpp:48
friend bool operator>(const type_t &lhs, const type_t &rhs) noexcept
Greater than or equal to comparison operator with specidied lhs ans rhs values.
Definition comparison_operators.hpp:57
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10