| 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 |
// [inout.ptr.t], class template inout_ptr_t |
| 14 |
// template<class Smart, class Pointer, class... Args> |
| 15 |
// class inout_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 = std::make_unique<int>(84); |
| 28 |
|
| 29 |
const std::inout_ptr_t<std::unique_ptr<int>, int*> ioPtr{uPtr}; |
| 30 |
|
| 31 |
static_assert(noexcept(ioPtr.operator int**())); |
| 32 |
std::same_as<int**> decltype(auto) pPtr = ioPtr.operator int**(); |
| 33 |
|
| 34 |
assert(**pPtr == 84); |
| 35 |
} |
| 36 |
|
| 37 |
{ |
| 38 |
std::unique_ptr<int, std::default_delete<int>> uPtr = std::make_unique<int>(84); |
| 39 |
|
| 40 |
const std::inout_ptr_t<decltype(uPtr), int*, std::default_delete<int>> ioPtr{uPtr, std::default_delete<int>{}}; |
| 41 |
|
| 42 |
static_assert(noexcept(ioPtr.operator int**())); |
| 43 |
std::same_as<int**> decltype(auto) pPtr = ioPtr.operator int**(); |
| 44 |
|
| 45 |
assert(**pPtr == 84); |
| 46 |
} |
| 47 |
|
| 48 |
// operator void**() |
| 49 |
{ |
| 50 |
std::unique_ptr<int> uPtr = std::make_unique<int>(84); |
| 51 |
|
| 52 |
const std::inout_ptr_t<std::unique_ptr<int>, void*> ioPtr{uPtr}; |
| 53 |
|
| 54 |
static_assert(noexcept(ioPtr.operator void**())); |
| 55 |
std::same_as<void**> decltype(auto) pPtr = ioPtr.operator void**(); |
| 56 |
|
| 57 |
assert(**reinterpret_cast<int**>(pPtr) == 84); |
| 58 |
} |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |