| 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, c++17, c++20 |
| 10 | |
| 11 | // <memory> |
| 12 | |
| 13 | // [out.ptr.t], class template out_ptr_t |
| 14 | // template<class Smart, class Pointer, class... Args> |
| 15 | // class out_ptr_t; // since c++23 |
| 16 | |
| 17 | // operator Pointer*() const noexcept; |
| 18 | // operator void**() const noexcept; |
| 19 | |
| 20 | #include <cassert> |
| 21 | #include <concepts> |
| 22 | #include <memory> |
| 23 | |
| 24 | int main(int, char**) { |
| 25 | // operator Pointer*() |
| 26 | { |
| 27 | std::unique_ptr<int> uPtr; |
| 28 | |
| 29 | const std::out_ptr_t<std::unique_ptr<int>, int*> oPtr{uPtr}; |
| 30 | |
| 31 | static_assert(noexcept(oPtr.operator int**())); |
| 32 | std::same_as<int**> decltype(auto) pPtr = oPtr.operator int**(); |
| 33 | |
| 34 | assert(*pPtr == nullptr); |
| 35 | } |
| 36 | |
| 37 | { |
| 38 | std::unique_ptr<int, std::default_delete<int>> uPtr; |
| 39 | |
| 40 | const std::out_ptr_t<decltype(uPtr), int*, std::default_delete<int>> oPtr{uPtr, std::default_delete<int>{}}; |
| 41 | |
| 42 | static_assert(noexcept(oPtr.operator int**())); |
| 43 | std::same_as<int**> decltype(auto) pPtr = oPtr.operator int**(); |
| 44 | |
| 45 | assert(*pPtr == nullptr); |
| 46 | } |
| 47 | |
| 48 | // operator void**() |
| 49 | { |
| 50 | std::unique_ptr<int> uPtr; |
| 51 | |
| 52 | const std::out_ptr_t<std::unique_ptr<int>, void*> oPtr{uPtr}; |
| 53 | |
| 54 | static_assert(noexcept(oPtr.operator void**())); |
| 55 | std::same_as<void**> decltype(auto) pPtr = oPtr.operator void**(); |
| 56 | |
| 57 | assert(*pPtr == nullptr); |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |