Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
hash_restriction_test.cc
Go to the documentation of this file.
1
2#include <gtest/gtest.h>
3#include <hash-fct.H>
4#include <string>
5#include <type_traits>
6#include <utility>
7#include <vector>
8
9using namespace Aleph;
10
11// This test doesn't actually run anything, it just checks for compilation
12// behavior (via type traits and decltype if needed, but here we can just
13// use a compile-time check for the existence of the overload)
14
15template<typename T, typename = void>
16struct is_hashable : std::false_type {};
17
18template<typename T>
19struct is_hashable<T, std::void_t<decltype(fnv_hash(std::declval<T>()))>> : std::true_type {};
20
21TEST(HashRestrictionTest, TriviallyCopyableTypesAreHashable)
22{
23 EXPECT_TRUE(is_hashable<int>::value);
24 EXPECT_TRUE(is_hashable<double>::value);
25
26 struct Simple { int a; char b; };
27 EXPECT_TRUE(is_hashable<Simple>::value);
28}
29
30TEST(HashRestrictionTest, NonTriviallyCopyableTypesAreNotHashable)
31{
32 // std::vector is NOT trivially copyable
33 EXPECT_FALSE(is_hashable<std::vector<int>>::value);
34}
35
36TEST(HashRestrictionTest, SpecialOverloadsStillWork)
37{
38 // std::string is NOT trivially copyable, but has a special overload
40
41 // const char* is a pointer (trivially copyable) and has overloads
43}
size_t size_t int32_t value
Definition ca-c-api.h:116
#define TEST(name)
Standard hash functions for Aleph types.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
STL namespace.