Debian Codegraph @

libcxx/test/std/experimental/memory/memory.observer.ptr/ctor.copy_move.pass.cpp

raw
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++03, c++11, c++14
11 // REQUIRES: c++experimental
12
13 // <experimental/memory>
14
15 // observer_ptr
16 //
17 // observer_ptr(const observer_ptr& other) = default;
18 // observer_ptr(observer_ptr&& other) = default;
19
20 #include <experimental/memory>
21 #include <cassert>
22 #include <type_traits>
23 #include <utility>
24
25 template <class T, class Object = T>
26 constexpr void test_copy_move() {
27 using Ptr = std::experimental::observer_ptr<T>;
28 Object obj;
29 {
30 Ptr ptr(&obj);
31 Ptr copy = ptr;
32 assert(ptr.get() == &obj);
33 assert(copy.get() == &obj);
34 static_assert(std::is_nothrow_copy_constructible<Ptr>::value);
35 }
36 {
37 Ptr ptr(&obj);
38 Ptr copy = std::move(ptr);
39 assert(ptr.get() == &obj);
40 assert(copy.get() == &obj);
41 static_assert(std::is_nothrow_move_constructible<Ptr>::value);
42 }
43 }
44
45 struct Bar {};
46
47 constexpr bool test() {
48 test_copy_move<int>();
49 test_copy_move<Bar>();
50 test_copy_move<void, int>();
51
52 return true;
53 }
54
55 int main(int, char**) {
56 test();
57 static_assert(test());
58
59 return 0;
60 }