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 | // explicit inout_ptr_t(Smart&, Args...); |
18 | |
19 | #include <cassert> |
20 | #include <memory> |
21 | |
22 | #include "test_convertible.h" |
23 | #include "../types.h" |
24 | |
25 | int main(int, char**) { |
26 | { |
27 | std::unique_ptr<int> uPtr; |
28 | |
29 | std::inout_ptr_t<std::unique_ptr<int>, int*>{uPtr}; |
30 | |
31 | static_assert( |
32 | !test_convertible<std::inout_ptr_t<std::unique_ptr<int>, int*>>(), "This constructor must be explicit" ); |
33 | |
34 | // Test the state of the pointer after construction. Complete tests are available in inout_ptr.general.pass.cpp. |
35 | assert(uPtr == nullptr); |
36 | } |
37 | |
38 | { |
39 | auto deleter = [](auto* p) { delete p; }; |
40 | std::unique_ptr<int, decltype(deleter)> uPtr; |
41 | |
42 | std::inout_ptr_t<std::unique_ptr<int, decltype(deleter)>, int*>{uPtr}; |
43 | |
44 | static_assert(!test_convertible<std::inout_ptr_t<std::unique_ptr<int, decltype(deleter)>, int*>>(), |
45 | "This constructor must be explicit" ); |
46 | |
47 | // Test the state of the pointer after construction. Complete tests are available in inout_ptr.general.pass.cpp. |
48 | assert(uPtr == nullptr); |
49 | } |
50 | |
51 | { |
52 | std::unique_ptr<int, MoveOnlyDeleter<int>> uPtr; |
53 | |
54 | std::inout_ptr_t<decltype(uPtr), int*, MoveOnlyDeleter<int>>{uPtr, MoveOnlyDeleter<int>{}}; |
55 | |
56 | // Test the state of the pointer after construction. Complete tests are available in inout_ptr.general.pass.cpp. |
57 | assert(uPtr == nullptr); |
58 | } |
59 | |
60 | return 0; |
61 | } |
62 | |