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