49 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410// REQUIRES: c++experimental11 12// <experimental/memory>13 14// observer_ptr15//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 23template <class T, class Object = T>24void 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 35struct Bar {};36 37void test() {38 test_make_observer<void, int>();39 test_make_observer<int>();40 test_make_observer<Bar>();41}42 43int main(int, char**) {44 // Note: this is not constexpr in the spec45 test();46 47 return 0;48}49