]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/shared_ptr/modifiers/reset_sfinae.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / shared_ptr / modifiers / reset_sfinae.cc
CommitLineData
99dee823 1// Copyright (C) 2016-2021 Free Software Foundation, Inc.
7663cae2
JW
2//
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)
7// any later version.
8
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.
13
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/>.
17
18// { dg-do compile { target c++11 } }
19
20#include <memory>
21
22template<typename T, typename Args, typename = void>
23 struct resettable
24 : std::false_type
25 { };
26
27template<typename... T> struct type_list { };
28
29template<typename T, typename... Args>
30 using reset_result
31 = decltype(std::shared_ptr<T>{}.reset(std::declval<Args>()...));
32
33template<typename T, typename... Args>
34 struct resettable<T, type_list<Args...>, reset_result<T, Args...>>
35 : std::true_type
36 { };
37
38template<typename T, typename... Args>
39constexpr bool can_reset()
40{ return resettable<T, type_list<Args...>>::value; }
41
42template<typename T>
43struct Deleter {
44 void operator()(T*) const;
45};
46
47template<typename T>
48using Alloc = std::allocator<T>;
49
50struct Base { };
51struct Derived : Base { };
52
53// Positive cases:
54
55static_assert( can_reset<const void, void*>(),
56 "void* convertible to const void*");
57static_assert( can_reset<const int, int*>(),
58 "int* convertible to const int*");
59static_assert( can_reset<Base, Derived*>(),
60 "Derived* convertible to Base*");
61static_assert( can_reset<const Base, Derived*>(),
62 "Derived* convertible to const Base*");
63
64// Negative cases:
65
66static_assert( !can_reset<int, void*>(),
67 "void* not convertible to int*");
68static_assert( !can_reset<int, void*, Deleter<int>>(),
69 "void* not convertible to int*");
70static_assert( !can_reset<int, void*, Deleter<int>, Alloc<int>>(),
71 "void* not convertible to int*");
72
73static_assert( !can_reset<int, const int*>(),
74 "const int* not convertible to int*");
75static_assert( !can_reset<int, const int*, Deleter<int>>(),
76 "const int* not convertible to int*");
77static_assert( !can_reset<int, const int*, Deleter<int>, Alloc<int>>(),
78 "const int* not convertible to int*");
79
80static_assert( !can_reset<int, long*>(),
81 "long* not convertible to int*");
82static_assert( !can_reset<int, long*, Deleter<int>>(),
83 "long* not convertible to int*");
84static_assert( !can_reset<int, long*, Deleter<int>, Alloc<int>>(),
85 "long* not convertible to int*");
86
87static_assert( !can_reset<Derived, Base*>(),
88 "Base* not convertible to Derived*");
89static_assert( !can_reset<Derived, Base*, Deleter<int>>(),
90 "Base* not convertible to Derived*");
91static_assert( !can_reset<Derived, Base*, Deleter<int>, Alloc<int>>(),
92 "Base* not convertible to Derived*");