xref: /llvm-project/libcxx/test/std/experimental/memory/memory.observer.ptr/hash.pass.cpp (revision 09e3a360581dc36d0820d3fb6da9bd7cfed87b5d)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 // REQUIRES: c++experimental
11 
12 // <experimental/memory>
13 
14 // observer_ptr
15 //
16 // template <class T> struct hash<std::experimental::observer_ptr<T>>;
17 
18 #include <experimental/memory>
19 #include <cassert>
20 #include <functional>
21 
22 #include "poisoned_hash_helper.h"
23 
24 template <class T, class Object = T>
25 void test_hash() {
26   {
27     using Ptr = std::experimental::observer_ptr<T>;
28     Object obj;
29     Ptr ptr(&obj);
30 
31     std::hash<std::experimental::observer_ptr<T>> f;
32     std::size_t h = f(ptr);
33 
34     assert(h == std::hash<T*>()(&obj));
35   }
36 
37   test_hash_enabled<std::experimental::observer_ptr<T>>();
38 }
39 
40 struct Bar {};
41 
42 void test() {
43   test_hash<void, int>();
44   test_hash<int>();
45   test_hash<Bar>();
46 }
47 
48 int main(int, char**) {
49   // Note: This isn't constexpr friendly in the spec!
50   test();
51 
52   return 0;
53 }
54