Porytiles
Loading...
Searching...
No Matches
artifact_key.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <compare>
4#include <functional>
5#include <string>
6
7namespace porytiles2 {
8
20 public:
26 explicit ArtifactKey(std::string key) : key_{std::move(key)} {}
27
33 [[nodiscard]] const std::string &key() const
34 {
35 return key_;
36 }
37
44 [[nodiscard]] bool operator==(const ArtifactKey &other) const = default;
45
52 [[nodiscard]] auto operator<=>(const ArtifactKey &other) const = default;
53
54 private:
55 std::string key_;
56};
57
58} // namespace porytiles2
59
60// Hash specialization for std::unordered_map support
61template <>
62struct std::hash<porytiles2::ArtifactKey> {
69 std::size_t operator()(const porytiles2::ArtifactKey &key) const noexcept
70 {
71 return std::hash<std::string>{}(key.key());
72 }
73};
A type-safe wrapper for artifact keys.
const std::string & key() const
Gets the underlying string value.
ArtifactKey(std::string key)
Constructs an ArtifactKey from a string value.
bool operator==(const ArtifactKey &other) const =default
Equality comparison operator.
auto operator<=>(const ArtifactKey &other) const =default
Three-way comparison operator for ordered containers.
std::size_t operator()(const porytiles2::ArtifactKey &key) const noexcept
Hash function for ArtifactKey.