1 // Copyright (C) 2016-2017 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++17" }
21 #include <type_traits>
23 #ifndef IS_NT_INVOCABLE_DEFINED
24 template<typename
... T
>
25 constexpr bool is_nt_invocable()
27 constexpr bool result
= std::is_nothrow_invocable_v
<T
...>;
28 static_assert(std::is_nothrow_invocable
<T
...>::value
== result
);
32 template<typename R
, typename
... T
>
33 constexpr bool is_nt_invocable_r()
35 constexpr bool result
= std::is_nothrow_invocable_r_v
<R
, T
...>;
36 static_assert(std::is_nothrow_invocable_r
<R
, T
...>::value
== result
);
43 struct T
{ T(int) { } };
44 struct NT
{ NT(int) noexcept
{ } };
45 struct Ex
{ explicit Ex(int) noexcept
{ } };
47 using func_type
= void(*)();
48 static_assert( ! is_nt_invocable
< func_type
>(), "");
50 #if __cpp_noexcept_function_type
51 using func_type_nt
= void(*)() noexcept
;
52 static_assert( is_nt_invocable
< func_type_nt
>(), "");
56 using mem_type
= int X::*;
58 static_assert( ! is_nt_invocable
< mem_type
>(), "");
59 static_assert( ! is_nt_invocable
< mem_type
, int >(), "");
60 static_assert( ! is_nt_invocable
< mem_type
, int& >(), "");
62 static_assert( is_nt_invocable
< mem_type
, X
& >(), "");
63 static_assert( is_nt_invocable_r
< int, mem_type
, X
& >(), "");
64 static_assert( is_nt_invocable_r
< int&, mem_type
, X
& >(), "");
65 static_assert( is_nt_invocable_r
< long, mem_type
, X
& >(), "");
66 static_assert( ! is_nt_invocable_r
< long&, mem_type
, X
& >(),
67 "conversion fails, cannot bind long& to int");
68 static_assert( is_nt_invocable_r
< int&, mem_type
, X
* >(), "");
70 static_assert( ! is_nt_invocable_r
< T
, mem_type
, X
& >(),
72 static_assert( is_nt_invocable_r
< NT
, mem_type
, X
& >(), "");
73 static_assert( ! is_nt_invocable_r
< Ex
, mem_type
, X
& >(),
74 "conversion fails, would use explicit constructor");
76 using memfun_type
= int (X::*)();
78 static_assert( ! is_nt_invocable
< memfun_type
>(), "no object");
79 static_assert( ! is_nt_invocable
< memfun_type
, int >(), "no object");
80 static_assert( ! is_nt_invocable
< memfun_type
, int& >(), "no object");
81 static_assert( ! is_nt_invocable
< memfun_type
, X
& >(), "call throws");
82 static_assert( ! is_nt_invocable
< memfun_type
, X
* >(), "call throws");
84 static_assert( ! is_nt_invocable_r
< T
, memfun_type
, X
& >(), "call throws");
85 static_assert( ! is_nt_invocable_r
< NT
, memfun_type
, X
& >(), "call throws");
86 static_assert( ! is_nt_invocable_r
< Ex
, memfun_type
, X
& >(), "call throws");
88 #if __cpp_noexcept_function_type
89 using memfun_type_nt
= int (X::*)() noexcept
;
91 static_assert( ! is_nt_invocable
< memfun_type_nt
>(), "no object");
92 static_assert( ! is_nt_invocable
< memfun_type_nt
, int >(), "no object");
93 static_assert( ! is_nt_invocable
< memfun_type_nt
, int& >(), "no object");
94 static_assert( is_nt_invocable
< memfun_type_nt
, X
& >(), "");
95 static_assert( is_nt_invocable
< memfun_type_nt
, X
* >(), "");
97 static_assert( ! is_nt_invocable_r
< T
, memfun_type_nt
, X
& >(),
99 static_assert( is_nt_invocable_r
< NT
, memfun_type_nt
, X
& >(), "");
100 static_assert( ! is_nt_invocable_r
< Ex
, memfun_type_nt
, X
& >(),
101 "conversion fails, would use explicit constructor");
106 long& operator()() const noexcept
;
107 short& operator()(int) &&;
108 char& operator()(int) const& noexcept
;
110 void operator()(int, int) noexcept
;
114 static_assert( ! is_nt_invocable
< F
>(), "call throws");
115 static_assert( is_nt_invocable
< CF
>(), "");
117 static_assert( ! is_nt_invocable_r
< int&, F
>(), "call throws");
118 static_assert( is_nt_invocable_r
< long&, CF
>(), "");
119 static_assert( ! is_nt_invocable_r
< T
, F
>(), "call throws");
120 static_assert( ! is_nt_invocable_r
< NT
, F
>(), "call throws");
121 static_assert( ! is_nt_invocable_r
< Ex
, F
>(), "call throws");
122 static_assert( ! is_nt_invocable_r
< T
, CF
>(), "conversion throws");
123 static_assert( is_nt_invocable_r
< NT
, CF
>(), "" );
124 static_assert( ! is_nt_invocable_r
< Ex
, CF
>(), "conversion fails");
126 static_assert( ! is_nt_invocable
< F
, int >(), "call throws");
127 static_assert( is_nt_invocable
< F
&, int >(), "");
129 static_assert( ! is_nt_invocable_r
< short&, F
, int >(),
131 static_assert( is_nt_invocable_r
< char&, F
&, int >(), "");
132 static_assert( ! is_nt_invocable_r
< T
, F
&, int >(),
133 "conversion throws");
134 static_assert( is_nt_invocable_r
< NT
, F
&, int >(), "");
135 static_assert( ! is_nt_invocable_r
< Ex
, F
&, int >(),
136 "conversion fails, would use explicit constructor");
138 static_assert( is_nt_invocable
< CF
, int >(), "");
139 static_assert( is_nt_invocable
< CF
&, int >(), "");
141 static_assert( is_nt_invocable_r
< char&, CF
, int >(), "");
142 static_assert( is_nt_invocable_r
< char&, CF
&, int >(), "");
144 static_assert( ! is_nt_invocable_r
< T
, CF
&, int >(),
145 "conversion throws");
146 static_assert( is_nt_invocable_r
< NT
, CF
&, int >(), "");
147 static_assert( ! is_nt_invocable_r
< Ex
, CF
&, int >(),
148 "conversion fails, would use explicit constructor");
150 static_assert( ! is_nt_invocable
< F
, int, int >(),
151 "would call private member");
152 static_assert( ! is_nt_invocable_r
<void, F
, int, int >(),
153 "would call private member");