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