diff --git a/octa/functional.hh b/octa/functional.hh index 7428607..413f892 100644 --- a/octa/functional.hh +++ b/octa/functional.hh @@ -6,6 +6,8 @@ #ifndef OCTA_FUNCTIONAL_HH #define OCTA_FUNCTIONAL_HH +#include + #include "octa/platform.hh" #include "octa/new.hh" #include "octa/memory.hh" @@ -321,21 +323,32 @@ template<> struct ToHash: octa::detail::ScalarHash } }; -template struct ToHash { - using Argument = T *; - using Result = octa::Size; +namespace detail { + template, char>::value> + struct ToHashPtr { + using Argument = T *; + using Result = octa::Size; + octa::Size operator()(T *v) const { + union { T *v; octa::Size h; } u; + u.v = v; + return octa::detail::mem_hash((const void *)&u, sizeof(u)); + } + }; - octa::Size operator()(T *v) const { - union { T *v; octa::Size h; } u; - u.v = v; - return octa::detail::mem_hash((const void *)&u, sizeof(u)); - } -}; + template struct ToHashPtr { + using Argument = T *; + using Result = octa::Size; + octa::Size operator()(T *v) const { + return octa::detail::mem_hash(v, strlen(v)); + } + }; +} + +template struct ToHash: octa::detail::ToHashPtr {}; template -typename ToHash>>::Result -to_hash(const T &v) { - return ToHash>>()(v); +typename ToHash::Result to_hash(const T &v) { + return ToHash()(v); } /* reference wrapper */