]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/io/lwg2948.cc
1 // Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
23 #include <testsuite_hooks.h>
25 template<typename S
, typename T
>
26 concept streamable
= requires (S
& o
, const T
& p
) { o
<< p
; };
28 template<typename T
, typename D
>
30 check(const std::unique_ptr
<T
, D
>& p
)
32 std::ostringstream ss1
, ss2
;
35 return ss1
.str() == ss2
.str();
41 static_assert( streamable
<std::ostream
, std::unique_ptr
<int>> );
43 std::unique_ptr
<int> p
;
45 p
= std::make_unique
<int>();
55 pointer(std::nullptr_t
) { }
56 explicit operator bool() const { return false; }
57 bool operator==(pointer
) const { return true; }
60 void operator()(pointer
) const { }
63 template<typename C
, typename Traits
>
65 operator<<(std::basic_ostream
<C
, Traits
>& o
, typename deleter
<C
>::pointer
&&)
68 return 1; // no requirement that this operator returns the stream
72 using Unique_ptr
= std::unique_ptr
<typename
D::pointer
, D
>;
74 static_assert( streamable
<std::ostream
, Unique_ptr
<deleter
<char>>> );
75 static_assert( ! streamable
<std::ostream
, Unique_ptr
<deleter
<wchar_t>>> );
76 static_assert( ! streamable
<std::wostream
, Unique_ptr
<deleter
<char>>> );
77 static_assert( streamable
<std::wostream
, Unique_ptr
<deleter
<wchar_t>>> );
82 Unique_ptr
<deleter
<char>> p
;