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