Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ set(MAIN_HEADERS
include/RemoteTools.h
include/Signal.hpp
include/TileTypes.h
include/TransHash.h
include/Types.h
include/VersionInfo.h
include/VersionInfoFactory.h
Expand Down
25 changes: 1 addition & 24 deletions library/include/DataDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ distribution.
#include "BitArray.h"
#include "Export.h"
#include "Format.h"
#include "TransHash.h"

struct lua_State;

Expand Down Expand Up @@ -364,30 +365,6 @@ namespace DFHack
virtual void build_metatable(lua_State *state) const;
};

namespace
{
template<typename ... Bases>
struct overload : Bases ...
{
using is_transparent = void;
using Bases::operator() ...;
};

struct char_pointer_hash
{
auto operator()(const char* ptr) const noexcept
{
return std::hash<std::string_view>{}(ptr);
}
};

using transparent_string_hash = overload<
std::hash<std::string>,
std::hash<std::string_view>,
char_pointer_hash
>;
}

#ifdef _MSC_VER
using virtual_ptr = void*;
#else
Expand Down
28 changes: 28 additions & 0 deletions library/include/TransHash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef TRANS_HASH_H
#define TRANS_HASH_H

namespace
{
template<typename ... Bases>
struct overload : Bases ...
{
using is_transparent = void;
using Bases::operator() ...;
};

struct char_pointer_hash
{
auto operator()(const char* ptr) const noexcept
{
return std::hash<std::string_view>{}(ptr);
}
};

using transparent_string_hash = overload<
std::hash<std::string>,
std::hash<std::string_view>,
char_pointer_hash
>;
}

#endif
Loading