]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_sfinae.cc
1 // Copyright (C) 2016-2023 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-do compile { target c++11 } }
19 // { dg-require-effective-target hosted }
23 template<typename T
, typename Args
, typename
= void>
28 template<typename
... T
> struct type_list
{ };
30 template<typename T
, typename
... Args
>
32 = decltype(std::shared_ptr
<T
>{}.reset(std::declval
<Args
>()...));
34 template<typename T
, typename
... Args
>
35 struct resettable
<T
, type_list
<Args
...>, reset_result
<T
, Args
...>>
39 template<typename T
, typename
... Args
>
40 constexpr bool can_reset()
41 { return resettable
<T
, type_list
<Args
...>>::value
; }
45 void operator()(T
*) const;
49 using Alloc
= std::allocator
<T
>;
52 struct Derived
: Base
{ };
56 static_assert( can_reset
<const void, void*>(),
57 "void* convertible to const void*");
58 static_assert( can_reset
<const int, int*>(),
59 "int* convertible to const int*");
60 static_assert( can_reset
<Base
, Derived
*>(),
61 "Derived* convertible to Base*");
62 static_assert( can_reset
<const Base
, Derived
*>(),
63 "Derived* convertible to const Base*");
67 static_assert( !can_reset
<int, void*>(),
68 "void* not convertible to int*");
69 static_assert( !can_reset
<int, void*, Deleter
<int>>(),
70 "void* not convertible to int*");
71 static_assert( !can_reset
<int, void*, Deleter
<int>, Alloc
<int>>(),
72 "void* not convertible to int*");
74 static_assert( !can_reset
<int, const int*>(),
75 "const int* not convertible to int*");
76 static_assert( !can_reset
<int, const int*, Deleter
<int>>(),
77 "const int* not convertible to int*");
78 static_assert( !can_reset
<int, const int*, Deleter
<int>, Alloc
<int>>(),
79 "const int* not convertible to int*");
81 static_assert( !can_reset
<int, long*>(),
82 "long* not convertible to int*");
83 static_assert( !can_reset
<int, long*, Deleter
<int>>(),
84 "long* not convertible to int*");
85 static_assert( !can_reset
<int, long*, Deleter
<int>, Alloc
<int>>(),
86 "long* not convertible to int*");
88 static_assert( !can_reset
<Derived
, Base
*>(),
89 "Base* not convertible to Derived*");
90 static_assert( !can_reset
<Derived
, Base
*, Deleter
<int>>(),
91 "Base* not convertible to Derived*");
92 static_assert( !can_reset
<Derived
, Base
*, Deleter
<int>, Alloc
<int>>(),
93 "Base* not convertible to Derived*");