xtd - Reference Guide 0.2.0
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:
21 
32  virtual int32_t compare_to(const object& obj) const noexcept {
33  if (!is<type_t>(&obj)) return 1;
34  return compare_to(static_cast<const type_t&>(obj));
35  }
36 
46  virtual int32_t compare_to(const type_t& obj) const noexcept = 0;
48 
50  // Not correct for an interface but necessary for C++ language.
51  bool operator<(const object& obj) const noexcept { return compare_to(obj) < 0; }
52  bool operator<=(const object& obj) const noexcept { return compare_to(obj) <= 0; }
53  bool operator>(const object& obj) const noexcept { return compare_to(obj) > 0; }
54  bool operator>=(const object& obj) const noexcept { return compare_to(obj) >= 0; }
55  bool operator<(const type_t& obj) const noexcept { return compare_to(obj) < 0; }
56  bool operator<=(const type_t& obj) const noexcept { return compare_to(obj) <= 0; }
57  bool operator>(const type_t& obj) const noexcept { return compare_to(obj) > 0; }
58  bool operator>=(const type_t& obj) const noexcept { return compare_to(obj) >= 0; }
60  };
61 }
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:32
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.