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

source code of libcxx/test/std/utilities/smartptr/adapt/out_ptr/out_ptr_t.ctor.pass.cpp