xtd 0.2.0
Loading...
Searching...
No Matches
hash_code.cpp

Shows how to use xtd::hash_code class.

#include <xtd/xtd>
using namespace xtd;
using namespace xtd::collections::generic;
struct order_order_line : public object, public iequatable<order_order_line> {
public:
order_order_line(int order_id, int order_line_id) : order_id_ {order_id}, order_line_id_ {order_line_id} {}
int order_id() const noexcept {return order_id_;}
int order_line_id() const noexcept {return order_line_id_;}
bool equals(const object& obj) const noexcept override {return is<order_order_line>(obj) && equals(as<order_order_line>(obj));}
bool equals(const order_order_line& other) const noexcept override {return order_id_ == other.order_id_ && order_line_id_ == other.order_line_id_;}
size get_hash_code() const noexcept override {return hash_code::combine(order_id_, order_line_id_);}
private:
int order_id_ = 0;
int order_line_id_ = 0;
};
auto main() -> int {
order_order_line {1, 1},
order_order_line {1, 1},
order_order_line {1, 2}
};
console::write_line("Item count: {}.", set.size());
}
// This code produces the following output :
//
// Item count: 2.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
std::unordered_set< type_t, helpers::hasher< type_t >, helpers::equator< type_t >, helpers::allocator< type_t > > hash_set
Represents a set of values.
Definition hash_set.h:33
size_t size
Represents a size of any object in bytes.
Definition size.h:23
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10