Debian Codegraph @

libcxx/test/std/experimental/memory/memory.observer.ptr/hash.pass.cpp

raw
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
21 #include "poisoned_hash_helper.h"
22
23 template <class T, class Object = T>
24 void test_hash() {
25 {
26 using Ptr = std::experimental::observer_ptr<T>;
27 Object obj;
28 Ptr ptr(&obj);
29
30 std::hash<std::experimental::observer_ptr<T>> f;
31 std::size_t h = f(ptr);
32
33 assert(h == std::hash<T*>()(&obj));
34 }
35
36 test_hash_enabled_for_type<std::experimental::observer_ptr<T>>();
37 }
38
39 struct Bar {};
40
41 void test() {
42 test_hash<void, int>();
43 test_hash<int>();
44 test_hash<Bar>();
45 }
46
47 int main(int, char**) {
48 // Note: This isn't constexpr friendly in the spec!
49 test();
50
51 return 0;
52 }