| 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 W> |
| 17 | // std::experimental::observer_ptr<W> make_observer(W* p) noexcept; |
| 18 | |
| 19 | #include <experimental/memory> |
| 20 | #include <cassert> |
| 21 | #include <type_traits> |
| 22 | |
| 23 | template <class T, class Object = T> |
| 24 | void test_make_observer() { |
| 25 | using Ptr = std::experimental::observer_ptr<T>; |
| 26 | Object obj; |
| 27 | T* raw = &obj; |
| 28 | |
| 29 | Ptr ptr = std::experimental::make_observer(raw); |
| 30 | assert(ptr.get() == raw); |
| 31 | static_assert(noexcept(std::experimental::make_observer(raw))); |
| 32 | static_assert(std::is_same<decltype(std::experimental::make_observer(raw)), Ptr>::value); |
| 33 | } |
| 34 | |
| 35 | struct Bar {}; |
| 36 | |
| 37 | void test() { |
| 38 | test_make_observer<void, int>(); |
| 39 | test_make_observer<int>(); |
| 40 | test_make_observer<Bar>(); |
| 41 | } |
| 42 | |
| 43 | int main(int, char**) { |
| 44 | // Note: this is not constexpr in the spec |
| 45 | test(); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |