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__
7#undef __XTD_STD_INTERNAL__
8
10namespace xtd {
27 template<typename type_t, typename comparable_t>
29 public:
31
37 friend bool operator <(const type_t& lhs, const type_t& rhs) noexcept {
38 auto rhs_ptr = &rhs;
39 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) < 0;
40 }
41
46 friend bool operator <=(const type_t& lhs, const type_t& rhs) noexcept {
47 auto rhs_ptr = &rhs;
48 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) <= 0;
49 }
50
55 friend bool operator >(const type_t& lhs, const type_t& rhs) noexcept {
56 auto rhs_ptr = &rhs;
57 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) > 0;
58 }
59
64 friend bool operator >=(const type_t& lhs, const type_t& rhs) noexcept {
65 auto rhs_ptr = &rhs;
66 return dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) >= 0;
67 }
68
69#if defined(__xtd__cpp_lib_three_way_comparison)
77 friend std::strong_ordering operator <=>(const type_t& lhs, const type_t& rhs) noexcept {
78 auto rhs_ptr = &rhs;
79 if (dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) < 0) return std::strong_ordering::less;
80 if (dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) > 0) return std::strong_ordering::greater;
81 if (dynamic_cast<const type_t*>(rhs_ptr) && lhs.compare_to(static_cast<const type_t&>(rhs)) == 0) return std::strong_ordering::equivalent;
82 return std::strong_ordering::less;
83 }
84#endif
86 private:
87 friend comparable_t;
88 comparison_operators() = default;
89 };
90}
Contains __xtd_std_version definitions.
Internal comparable operators definition.
Definition comparison_operators.hpp:28
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:77
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:37
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:64
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:46
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:55
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10