1*053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 2*053d81ceSMarshall Clow // 3*053d81ceSMarshall Clow // The LLVM Compiler Infrastructure 4*053d81ceSMarshall Clow // 5*053d81ceSMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open 6*053d81ceSMarshall Clow // Source Licenses. See LICENSE.TXT for details. 7*053d81ceSMarshall Clow // 8*053d81ceSMarshall Clow //===----------------------------------------------------------------------===// 9*053d81ceSMarshall Clow 10*053d81ceSMarshall Clow // <functional> 11*053d81ceSMarshall Clow 12*053d81ceSMarshall Clow // template <class T> 13*053d81ceSMarshall Clow // struct hash 14*053d81ceSMarshall Clow // : public unary_function<T, size_t> 15*053d81ceSMarshall Clow // { 16*053d81ceSMarshall Clow // size_t operator()(T val) const; 17*053d81ceSMarshall Clow // }; 18*053d81ceSMarshall Clow 19*053d81ceSMarshall Clow // Not very portable 20*053d81ceSMarshall Clow 21*053d81ceSMarshall Clow #include <string_view> 22*053d81ceSMarshall Clow #include <cassert> 23*053d81ceSMarshall Clow #include <type_traits> 24*053d81ceSMarshall Clow 25*053d81ceSMarshall Clow using std::string_view; 26*053d81ceSMarshall Clow 27*053d81ceSMarshall Clow template <class T> 28*053d81ceSMarshall Clow void 29*053d81ceSMarshall Clow test() 30*053d81ceSMarshall Clow { 31*053d81ceSMarshall Clow typedef std::hash<T> H; 32*053d81ceSMarshall Clow static_assert((std::is_same<typename H::argument_type, T>::value), "" ); 33*053d81ceSMarshall Clow static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); 34*053d81ceSMarshall Clow H h; 35*053d81ceSMarshall Clow // std::string g1 = "1234567890"; 36*053d81ceSMarshall Clow // std::string g2 = "1234567891"; 37*053d81ceSMarshall Clow typedef typename T::value_type char_type; 38*053d81ceSMarshall Clow char_type g1 [ 10 ]; 39*053d81ceSMarshall Clow char_type g2 [ 10 ]; 40*053d81ceSMarshall Clow for ( int i = 0; i < 10; ++i ) 41*053d81ceSMarshall Clow g1[i] = g2[9-i] = '0' + i; 42*053d81ceSMarshall Clow T s1(g1, 10); 43*053d81ceSMarshall Clow T s2(g2, 10); 44*053d81ceSMarshall Clow assert(h(s1) != h(s2)); 45*053d81ceSMarshall Clow } 46*053d81ceSMarshall Clow 47*053d81ceSMarshall Clow int main() 48*053d81ceSMarshall Clow { 49*053d81ceSMarshall Clow test<std::string_view>(); 50*053d81ceSMarshall Clow #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 51*053d81ceSMarshall Clow test<std::u16string_view>(); 52*053d81ceSMarshall Clow test<std::u32string_view>(); 53*053d81ceSMarshall Clow #endif // _LIBCPP_HAS_NO_UNICODE_CHARS 54*053d81ceSMarshall Clow test<std::wstring_view>(); 55*053d81ceSMarshall Clow } 56