xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
icomparable.h
Go to the documentation of this file.
1 #pragma once
5 #include "interface.h"
6 #include "object.h"
7 #include "is.h"
8 
10 namespace xtd {
17  template <typename type_t>
19  public:
29  virtual int32_t compare_to(const object& obj) const noexcept {
30  if (!is<type_t>(&obj)) return 1;
31  return compare_to(static_cast<const type_t&>(obj));
32  }
33 
43  virtual int32_t compare_to(const type_t& obj) const noexcept = 0;
44 
46  // Not correct for an interface but necessary for C++ language.
47  bool operator<(const object& obj) const noexcept { return compare_to(obj) < 0; }
48  bool operator<=(const object& obj) const noexcept { return compare_to(obj) <= 0; }
49  bool operator>(const object& obj) const noexcept { return compare_to(obj) > 0; }
50  bool operator>=(const object& obj) const noexcept { return compare_to(obj) >= 0; }
51  bool operator<(const type_t& obj) const noexcept { return compare_to(obj) < 0; }
52  bool operator<=(const type_t& obj) const noexcept { return compare_to(obj) <= 0; }
53  bool operator>(const type_t& obj) const noexcept { return compare_to(obj) > 0; }
54  bool operator>=(const type_t& obj) const noexcept { return compare_to(obj) >= 0; }
56  };
57 }
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition: icomparable.h:18
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
virtual int32_t compare_to(const object &obj) const noexcept
Compares the current instance with another object of the same type.
Definition: icomparable.h:29
Contains xtd::interface interface.
#define interface_
This keyword is use to represent an interface.
Definition: interface.h:55
Contains xtd::object class.
Contains xtd::is method.