Debian Codegraph @

libstdc++-v3/testsuite/20_util/void_t/1.cc

raw
1 // Copyright (C) 2015-2025 Free Software Foundation, Inc.
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++17 } }
19 // { dg-add-options no_pch }
20
21 #include <type_traits>
22
23 #ifndef __cpp_lib_void_t
24 # error "Feature-test macro for void_t missing"
25 #elif __cpp_lib_void_t != 201411
26 # error "Feature-test macro for void_t has wrong value"
27 #endif
28
29 static_assert( std::is_same<std::void_t<int, long, double>, void>::value,
30 "void_t is a synonym for void" );
31
32 struct X { };
33 X operator+(const X& x) { return x; }
34
35 template<typename T, typename U = std::void_t<>>
36 struct has_unary_plus
37 : std::false_type
38 { };
39
40 template<typename T>
41 struct has_unary_plus<T, std::void_t<decltype(+std::declval<X>())>>
42 : std::true_type
43 { };
44
45 static_assert( has_unary_plus<X>::value, "void_t detects valid expressions" );