brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · eae5d51 Raw
51 lines · cpp
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-exception7//8//===----------------------------------------------------------------------===//9 10// UNSUPPORTED: c++03, c++11, c++1411// REQUIRES: c++experimental12 13// <experimental/memory>14 15// observer_ptr16//17// constexpr element_type* get() const noexcept;18 19#include <experimental/memory>20#include <type_traits>21#include <cassert>22 23template <class T, class Object = T>24constexpr 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 35struct Bar {};36 37constexpr bool test() {38  test_get<Bar>();39  test_get<int>();40  test_get<void, int>();41 42  return true;43}44 45int main(int, char**) {46  test();47  static_assert(test());48 49  return 0;50}51