xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
icomparable.h
Go to the documentation of this file.
1
4#pragma once
5#include "interface.h"
6#include "object.h"
7#include "is.h"
8
10namespace 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
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
virtual int32_t 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:55
Contains xtd::interface interface.
Contains xtd::is method.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.