]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_sfinae.cc
1 // Copyright (C) 2016-2020 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 } }
22 template<typename T
, typename Args
, typename
= void>
27 template<typename
... T
> struct type_list
{ };
29 template<typename T
, typename
... Args
>
31 = decltype(std::shared_ptr
<T
>{}.reset(std::declval
<Args
>()...));
33 template<typename T
, typename
... Args
>
34 struct resettable
<T
, type_list
<Args
...>, reset_result
<T
, Args
...>>
38 template<typename T
, typename
... Args
>
39 constexpr bool can_reset()
40 { return resettable
<T
, type_list
<Args
...>>::value
; }
44 void operator()(T
*) const;
48 using Alloc
= std::allocator
<T
>;
51 struct Derived
: Base
{ };
55 static_assert( can_reset
<const void, void*>(),
56 "void* convertible to const void*");
57 static_assert( can_reset
<const int, int*>(),
58 "int* convertible to const int*");
59 static_assert( can_reset
<Base
, Derived
*>(),
60 "Derived* convertible to Base*");
61 static_assert( can_reset
<const Base
, Derived
*>(),
62 "Derived* convertible to const Base*");
66 static_assert( !can_reset
<int, void*>(),
67 "void* not convertible to int*");
68 static_assert( !can_reset
<int, void*, Deleter
<int>>(),
69 "void* not convertible to int*");
70 static_assert( !can_reset
<int, void*, Deleter
<int>, Alloc
<int>>(),
71 "void* not convertible to int*");
73 static_assert( !can_reset
<int, const int*>(),
74 "const int* not convertible to int*");
75 static_assert( !can_reset
<int, const int*, Deleter
<int>>(),
76 "const int* not convertible to int*");
77 static_assert( !can_reset
<int, const int*, Deleter
<int>, Alloc
<int>>(),
78 "const int* not convertible to int*");
80 static_assert( !can_reset
<int, long*>(),
81 "long* not convertible to int*");
82 static_assert( !can_reset
<int, long*, Deleter
<int>>(),
83 "long* not convertible to int*");
84 static_assert( !can_reset
<int, long*, Deleter
<int>, Alloc
<int>>(),
85 "long* not convertible to int*");
87 static_assert( !can_reset
<Derived
, Base
*>(),
88 "Base* not convertible to Derived*");
89 static_assert( !can_reset
<Derived
, Base
*, Deleter
<int>>(),
90 "Base* not convertible to Derived*");
91 static_assert( !can_reset
<Derived
, Base
*, Deleter
<int>, Alloc
<int>>(),
92 "Base* not convertible to Derived*");