xtd 0.2.0
icomparable.h
Go to the documentation of this file.
1 #pragma once
5 #include "interface.h"
6 #include "types.h"
7 
9 namespace xtd {
16  template <typename type_t>
18  public:
20 
31  virtual int32 compare_to(const type_t& obj) const noexcept = 0;
33 
35  friend bool operator <(const type_t& a, const type_t& b) noexcept {return a.compare_to(b) < 0;}
36  friend bool operator <=(const type_t& a, const type_t& b) noexcept {return a.compare_to(b) <= 0;}
37  friend bool operator >(const type_t& a, const type_t& b) noexcept {return a.compare_to(b) > 0;}
38  friend bool operator >=(const type_t& a, const type_t& b) noexcept {return a.compare_to(b) >= 0;}
39  template<typename object_t>
40  friend bool operator <(const type_t& a, const icomparable<object_t>& b) noexcept {return dynamic_cast<const type_t*>(&b) && a.compare_to(dynamic_cast<const type_t&>(b)) < 0;}
41  template<typename object_t>
42  friend bool operator <=(const type_t& a, const icomparable<object_t>& b) noexcept {return dynamic_cast<const type_t*>(&b) && a.compare_to(dynamic_cast<const type_t&>(b)) <= 0;}
43  template<typename object_t>
44  friend bool operator >(const type_t& a, const icomparable<object_t>& b) noexcept {return dynamic_cast<const type_t*>(&b) && a.compare_to(dynamic_cast<const type_t&>(b)) > 0;}
45  template<typename object_t>
46  friend bool operator >=(const type_t& a, const icomparable<object_t>& b) noexcept {return dynamic_cast<const type_t*>(&b) && a.compare_to(dynamic_cast<const type_t&>(b)) >= 0;}
48  };
49 }
Contains xtd fundamental types.
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition: icomparable.h:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::interface interface.
virtual int32 compare_to(const type_t &obj) const noexcept=0
Compares the current instance with another object of the same type.
#define interface_
This keyword is use to represent an interface.
Definition: interface.h:54
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129