xtd 0.2.0
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.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static xtd::size combine(args_t... values) noexcept
Combines values into a hash code.
Definition hash_code.hpp:70
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
std::unordered_set< type_t, hasher_t, equator_t, allocator_t > hash_set
Represents a set of values.
Definition hash_set.hpp:34
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:365
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ other
The operating system is other.
Definition platform_id.hpp:58
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:272
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:296