1#ifndef NEFORCE_CORE_INTERFACE_ICOMMON_HPP__
2#define NEFORCE_CORE_INTERFACE_ICOMMON_HPP__
13NEFORCE_BEGIN_NAMESPACE__
32 constexpr const T& derived()
const noexcept {
return static_cast<const T&
>(*this); }
41 NEFORCE_NODISCARD
constexpr size_t to_ihash() const noexcept(noexcept(derived().to_hash())) {
42 return derived().to_hash();
59 NEFORCE_NODISCARD
constexpr size_t operator()(
const T& obj)
const noexcept(
noexcept(obj.to_ihash())) {
60 return obj.to_ihash();
82 constexpr const T& derived()
const noexcept {
return static_cast<const T&
>(*this); }
92 NEFORCE_NODISCARD
constexpr bool operator==(
const T& rhs)
const noexcept(
noexcept(derived().equal_to(rhs))) {
93 return derived().equal_to(rhs);
103 NEFORCE_NODISCARD
constexpr bool operator!=(
const T& rhs)
const noexcept(
noexcept(!(derived().equal_to(rhs)))) {
104 return !(derived().equal_to(rhs));
114 NEFORCE_NODISCARD
constexpr bool operator<(
const T& rhs)
const noexcept(
noexcept(derived().less_than(rhs))) {
115 return derived().less_than(rhs);
125 NEFORCE_NODISCARD
constexpr bool operator>(
const T& rhs)
const noexcept(
noexcept(rhs.less_than(derived()))) {
126 return rhs.less_than(derived());
136 NEFORCE_NODISCARD
constexpr bool operator<=(
const T& rhs)
const noexcept(
noexcept(!(rhs.less_than(derived())))) {
137 return !(rhs.less_than(derived()));
147 NEFORCE_NODISCARD
constexpr bool operator>=(
const T& rhs)
const noexcept(
noexcept(!(derived().less_than(rhs)))) {
148 return !(derived().less_than(rhs));
152template <
typename T, enable_if_t<is_base_of_v<icomparable<T>, T>,
int> = 0>
153NEFORCE_NODISCARD
constexpr bool operator==(
const T& lhs,
const T& rhs) {
154 return lhs.equal_to(rhs);
157template <
typename T, enable_if_t<is_base_of_v<icomparable<T>, T>,
int> = 0>
158NEFORCE_NODISCARD
constexpr bool operator!=(
const T& lhs,
const T& rhs) {
159 return !(lhs.equal_to(rhs));
162template <
typename T, enable_if_t<is_base_of_v<icomparable<T>, T>,
int> = 0>
163NEFORCE_NODISCARD
constexpr bool operator<(
const T& lhs,
const T& rhs) {
164 return lhs.less_than(rhs);
167template <
typename T, enable_if_t<is_base_of_v<icomparable<T>, T>,
int> = 0>
168NEFORCE_NODISCARD
constexpr bool operator>(
const T& lhs,
const T& rhs) {
169 return rhs.less_than(lhs);
172template <
typename T, enable_if_t<is_base_of_v<icomparable<T>, T>,
int> = 0>
173NEFORCE_NODISCARD
constexpr bool operator<=(
const T& lhs,
const T& rhs) {
174 return !(rhs.less_than(lhs));
177template <
typename T, enable_if_t<is_base_of_v<icomparable<T>, T>,
int> = 0>
178NEFORCE_NODISCARD
constexpr bool operator>=(
const T& lhs,
const T& rhs) {
179 return !(lhs.less_than(rhs));
197NEFORCE_END_NAMESPACE__
bool operator!=(const function< Res(Args...)> &f, nullptr_t np) noexcept
不等于空指针比较
bool operator==(const function< Res(Args...)> &f, nullptr_t np) noexcept
等于空指针比较
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
constexpr bool operator<=(const T &rhs) const noexcept(noexcept(!(rhs.less_than(derived()))))
小于等于比较运算符
constexpr bool operator>=(const T &rhs) const noexcept(noexcept(!(derived().less_than(rhs))))
大于等于比较运算符
constexpr bool operator==(const T &rhs) const noexcept(noexcept(derived().equal_to(rhs)))
相等比较运算符
constexpr bool operator!=(const T &rhs) const noexcept(noexcept(!(derived().equal_to(rhs))))
不等比较运算符
constexpr bool operator>(const T &rhs) const noexcept(noexcept(rhs.less_than(derived())))
大于比较运算符
constexpr bool operator<(const T &rhs) const noexcept(noexcept(derived().less_than(rhs)))
小于比较运算符
constexpr size_t to_ihash() const noexcept(noexcept(derived().to_hash()))
获取对象的哈希值