Introduce hash.lookup.isHashFunction trait

Fix #66.
This commit is contained in:
2018-09-14 15:16:08 +02:00
parent b6d1766d58
commit b831a05407
3 changed files with 28 additions and 4 deletions

View File

@ -386,7 +386,7 @@ struct ByValue(T)
* hasher = Hash function for $(D_PARAM Key).
*/
struct HashTable(Key, Value, alias hasher = hash)
if (is(typeof(((Key k) => hasher(k))(Key.init)) == size_t))
if (isHashFunction!(hasher, Key))
{
private alias HashArray = .HashArray!(hasher, Key, Value);
private alias Buckets = HashArray.Buckets;

View File

@ -154,7 +154,7 @@ struct Range(T)
* hasher = Hash function for $(D_PARAM T).
*/
struct Set(T, alias hasher = hash)
if (is(typeof(((T x) => hasher(x))(T.init)) == size_t))
if (isHashFunction!(hasher, T))
{
private alias HashArray = .HashArray!(hasher, T);
private alias Buckets = HashArray.Buckets;
@ -768,8 +768,8 @@ if (is(typeof(((T x) => hasher(x))(T.init)) == size_t))
testFunc(set);
}
// Hasher can take argument by ref
@nogc nothrow pure @safe unittest
{
// Using hasher that takes argument by ref.
Set!(int, (const ref x) => cast(size_t)x) set;
static assert(is(Set!(int, (const ref x) => cast(size_t) x)));
}