Added libfmt support for Name.

This commit is contained in:
Patrick 2023-11-26 15:13:06 +01:00
parent c44350269a
commit 27b163f4db

View File

@ -6,6 +6,9 @@
#include <limits>
#include <string_view>
#if __has_include(<fmt/format.h>)
# include <fmt/format.h>
#endif
namespace mijin
{
@ -49,15 +52,24 @@ public:
} // namespace mijin
namespace std
{
template<>
struct hash<mijin::Name> : hash<std::size_t>
struct std::hash<mijin::Name> : hash<std::size_t>
{
std::size_t operator()(mijin::Name name) const noexcept {
return hash<std::size_t>::operator()(name.getID());
}
};
}
#if __has_include(<fmt/format.h>)
template<>
struct fmt::formatter<mijin::Name> : fmt::formatter<std::string_view>
{
template<typename TContext>
auto format(mijin::Name name, TContext& ctx) const -> decltype(ctx.out())
{
return fmt::formatter<std::string_view>::format(name.stringView(), ctx);
}
};
#endif // __has_include(<fmt/format.h>)
#endif // !defined(MIJIN_TYPES_NAME_HPP_INCLUDED)