1053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2053d81ceSMarshall Clow //
3053d81ceSMarshall Clow //                     The LLVM Compiler Infrastructure
4053d81ceSMarshall Clow //
5053d81ceSMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open
6053d81ceSMarshall Clow // Source Licenses. See LICENSE.TXT for details.
7053d81ceSMarshall Clow //
8053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
9053d81ceSMarshall Clow 
10053d81ceSMarshall Clow // <functional>
11053d81ceSMarshall Clow 
12053d81ceSMarshall Clow // template <class T>
13053d81ceSMarshall Clow // struct hash
14053d81ceSMarshall Clow //     : public unary_function<T, size_t>
15053d81ceSMarshall Clow // {
16053d81ceSMarshall Clow //     size_t operator()(T val) const;
17053d81ceSMarshall Clow // };
18053d81ceSMarshall Clow 
19053d81ceSMarshall Clow // Not very portable
20053d81ceSMarshall Clow 
21053d81ceSMarshall Clow #include <string_view>
22053d81ceSMarshall Clow #include <cassert>
23053d81ceSMarshall Clow #include <type_traits>
24053d81ceSMarshall Clow 
25053d81ceSMarshall Clow using std::string_view;
26053d81ceSMarshall Clow 
27053d81ceSMarshall Clow template <class T>
28053d81ceSMarshall Clow void
29053d81ceSMarshall Clow test()
30053d81ceSMarshall Clow {
31053d81ceSMarshall Clow     typedef std::hash<T> H;
32053d81ceSMarshall Clow     static_assert((std::is_same<typename H::argument_type, T>::value), "" );
33053d81ceSMarshall Clow     static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
34053d81ceSMarshall Clow     H h;
35053d81ceSMarshall Clow //     std::string g1 = "1234567890";
36053d81ceSMarshall Clow //     std::string g2 = "1234567891";
37053d81ceSMarshall Clow     typedef typename T::value_type char_type;
38053d81ceSMarshall Clow     char_type g1 [ 10 ];
39053d81ceSMarshall Clow     char_type g2 [ 10 ];
40053d81ceSMarshall Clow     for ( int i = 0; i < 10; ++i )
41*f2e24f56SStephan T. Lavavej         g1[i] = g2[9-i] = static_cast<char_type>('0' + i);
42053d81ceSMarshall Clow     T s1(g1, 10);
43053d81ceSMarshall Clow     T s2(g2, 10);
44053d81ceSMarshall Clow     assert(h(s1) != h(s2));
45053d81ceSMarshall Clow }
46053d81ceSMarshall Clow 
47053d81ceSMarshall Clow int main()
48053d81ceSMarshall Clow {
49053d81ceSMarshall Clow     test<std::string_view>();
50053d81ceSMarshall Clow #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
51053d81ceSMarshall Clow     test<std::u16string_view>();
52053d81ceSMarshall Clow     test<std::u32string_view>();
53053d81ceSMarshall Clow #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
54053d81ceSMarshall Clow     test<std::wstring_view>();
55053d81ceSMarshall Clow }
56