Commit cfc219ae by Jonathan Wakely Committed by Jonathan Wakely

Implement <concepts> header for C++20

There are currently no tests for [concepts.compare], but they will be
added ASAP.

	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Include <concepts>.
	* include/std/concepts: New header for C++20.
	* include/std/version (__cpp_lib_concepts): Define.
	* scripts/create_testsuite_files: Look for test files in new std
	directory.
	* testsuite/libstdc++-dg/conformance.exp: Likewise.
	* testsuite/std/concepts/concepts.callable/invocable.cc: New test.
	* testsuite/std/concepts/concepts.callable/regular_invocable.cc: New
	test.
	* testsuite/std/concepts/concepts.callable/relation.cc: New test.
	* testsuite/std/concepts/concepts.callable/strictweakorder.cc: New
	test.
	* testsuite/std/concepts/concepts.lang/concept.arithmetic/
	floating_point.cc: New test.
	* testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.arithmetic/
	signed_integral.cc: New test.
	* testsuite/std/concepts/concepts.lang/concept.arithmetic/
	unsigned_integral.cc: New test.
	* testsuite/std/concepts/concepts.lang/concept.assignable/1.cc: New
	test.
	* testsuite/std/concepts/concepts.lang/concept.common/1.cc: New test.
	* testsuite/std/concepts/concepts.lang/concept.commonref/1.cc: New
	test.
	* testsuite/std/concepts/concepts.lang/concept.constructible/1.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.convertible/1.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.defaultconstructible/
	1.cc: New test.
	* testsuite/std/concepts/concepts.lang/concept.derived/1.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.destructible/1.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.same/1.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc:
	New test.
	* testsuite/std/concepts/concepts.lang/concept.swappable/
	swappable_with.cc: New test.
	* testsuite/std/concepts/concepts.object/copyable.cc: New test.
	* testsuite/std/concepts/concepts.object/movable.cc: New test.
	* testsuite/std/concepts/concepts.object/regular.cc: New test.
	* testsuite/std/concepts/concepts.object/semiregular.cc: New test.

From-SVN: r276892
parent 02f6fdff
2019-10-11 Jonathan Wakely <jwakely@redhat.com>
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Include <concepts>.
* include/std/concepts: New header for C++20.
* include/std/version (__cpp_lib_concepts): Define.
* scripts/create_testsuite_files: Look for test files in new std
directory.
* testsuite/libstdc++-dg/conformance.exp: Likewise.
* testsuite/std/concepts/concepts.callable/invocable.cc: New test.
* testsuite/std/concepts/concepts.callable/regular_invocable.cc: New
test.
* testsuite/std/concepts/concepts.callable/relation.cc: New test.
* testsuite/std/concepts/concepts.callable/strictweakorder.cc: New
test.
* testsuite/std/concepts/concepts.lang/concept.arithmetic/
floating_point.cc: New test.
* testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.arithmetic/
signed_integral.cc: New test.
* testsuite/std/concepts/concepts.lang/concept.arithmetic/
unsigned_integral.cc: New test.
* testsuite/std/concepts/concepts.lang/concept.assignable/1.cc: New
test.
* testsuite/std/concepts/concepts.lang/concept.common/1.cc: New test.
* testsuite/std/concepts/concepts.lang/concept.commonref/1.cc: New
test.
* testsuite/std/concepts/concepts.lang/concept.constructible/1.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.convertible/1.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.copyconstructible/1.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.defaultconstructible/
1.cc: New test.
* testsuite/std/concepts/concepts.lang/concept.derived/1.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.destructible/1.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.moveconstructible/1.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.same/1.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc:
New test.
* testsuite/std/concepts/concepts.lang/concept.swappable/
swappable_with.cc: New test.
* testsuite/std/concepts/concepts.object/copyable.cc: New test.
* testsuite/std/concepts/concepts.object/movable.cc: New test.
* testsuite/std/concepts/concepts.object/regular.cc: New test.
* testsuite/std/concepts/concepts.object/semiregular.cc: New test.
* include/std/type_traits (is_same): Replace partial specialization
by using __is_same_as built-in in primary template.
(is_same_v): Use __is_same_as built-in instead of instantiating the
......
......@@ -36,6 +36,7 @@ std_headers = \
${std_srcdir}/chrono \
${std_srcdir}/codecvt \
${std_srcdir}/complex \
${std_srcdir}/concepts \
${std_srcdir}/condition_variable \
${std_srcdir}/deque \
${std_srcdir}/execution \
......@@ -1379,8 +1380,8 @@ endif
# This is a subset of the full install-headers rule. We only need <ciso646>,
# <cstddef>, <cfloat>, <limits>, <climits>, <version>, <cstdint>, <cstdlib>,
# <new>, <typeinfo>, <exception>, <initializer_list>, <cstdalign>, <cstdarg>,
# <cstdbool>, <type_traits>, <bit>, <atomic>, and any files which they include
# (and which we provide).
# <concepts>, <cstdbool>, <type_traits>, <bit>, <atomic>,
# and any files which they include (and which we provide).
# <new>, <typeinfo>, <exception>, and <initializer_list> are installed by
# libsupc++, so only the others and the sub-includes are copied here.
install-freestanding-headers:
......@@ -1393,7 +1394,7 @@ install-freestanding-headers:
${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \
$(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir}
for file in limits type_traits atomic bit version; do \
for file in limits type_traits atomic bit concepts version; do \
$(INSTALL_DATA) ${std_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${std_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
for file in ciso646 cstddef cfloat climits cstdint cstdlib \
......
......@@ -380,6 +380,7 @@ std_headers = \
${std_srcdir}/chrono \
${std_srcdir}/codecvt \
${std_srcdir}/complex \
${std_srcdir}/concepts \
${std_srcdir}/condition_variable \
${std_srcdir}/deque \
${std_srcdir}/execution \
......@@ -1853,8 +1854,8 @@ ${pch3_output}: ${pch3_source} ${pch2_output}
# This is a subset of the full install-headers rule. We only need <ciso646>,
# <cstddef>, <cfloat>, <limits>, <climits>, <version>, <cstdint>, <cstdlib>,
# <new>, <typeinfo>, <exception>, <initializer_list>, <cstdalign>, <cstdarg>,
# <cstdbool>, <type_traits>, <bit>, <atomic>, and any files which they include
# (and which we provide).
# <concepts>, <cstdbool>, <type_traits>, <bit>, <atomic>,
# and any files which they include (and which we provide).
# <new>, <typeinfo>, <exception>, and <initializer_list> are installed by
# libsupc++, so only the others and the sub-includes are copied here.
install-freestanding-headers:
......@@ -1867,7 +1868,7 @@ install-freestanding-headers:
${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h; do \
$(INSTALL_DATA) $${file} $(DESTDIR)${host_installdir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${std_builddir}
for file in limits type_traits atomic bit version; do \
for file in limits type_traits atomic bit concepts version; do \
$(INSTALL_DATA) ${std_builddir}/$${file} $(DESTDIR)${gxx_include_dir}/${std_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${c_base_builddir}
for file in ciso646 cstddef cfloat climits cstdint cstdlib \
......
......@@ -136,7 +136,7 @@
#if __cplusplus > 201703L
#include <bit>
// #include <compare>
// #include <concepts>
#include <concepts>
#include <numbers>
// #include <ranges>
#include <span>
......
......@@ -153,6 +153,9 @@
#define __cpp_lib_atomic_ref 201806L
#define __cpp_lib_bind_front 201907L
#define __cpp_lib_bounded_array_traits 201902L
#if __cpp_concepts
# define __cpp_lib_concepts 201806L
#endif
#define __cpp_lib_constexpr 201711L
#define __cpp_lib_constexpr_algorithms 201806L
#if __cpp_impl_destroying_delete
......
......@@ -33,7 +33,7 @@ cd $srcdir
# what has to happen when find(1) doesn't support -mindepth, or -xtype.
# The directories here should be consistent with libstdc++-dg/conformance.exp
dlist=`echo [0-9][0-9]*`
dlist="$dlist abi backward ext performance tr1 tr2 decimal experimental"
dlist="$dlist std abi backward ext performance tr1 tr2 decimal experimental"
dlist="$dlist special_functions"
find $dlist "(" -type f -o -type l ")" -name "*.cc" -print > $tmp.01
find $dlist "(" -type f -o -type l ")" -name "*.c" -print > $tmp.02
......
......@@ -54,6 +54,7 @@ if {[info exists tests_file] && [file exists $tests_file]} {
# Find directories that might have tests.
# This list should be consistent with scripts/create_testsuite_files
set subdirs [glob "$srcdir/\[0-9\]\[0-9\]*"]
lappend subdirs "$srcdir/std"
lappend subdirs "$srcdir/abi"
lappend subdirs "$srcdir/backward"
lappend subdirs "$srcdir/ext"
......
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( ! std::invocable<int> );
static_assert( std::invocable<int()> );
static_assert( std::invocable<int(*)()> );
static_assert( std::invocable<int(&)()> );
static_assert( ! std::invocable<int(), int> );
static_assert( ! std::invocable<int() const> );
static_assert( std::invocable<int(const long*, short), long*, char> );
struct A;
static_assert( std::invocable<int A::*, const A&> );
static_assert( ! std::invocable<void (A::*)(long&), const A*, long&> );
static_assert( std::invocable<void (A::*)(long&) const, A*, long&> );
struct F
{
void operator()() const;
void operator()(int);
};
static_assert( std::invocable<F> );
static_assert( std::invocable<F, int> );
static_assert( std::invocable<const F&> );
static_assert( ! std::invocable<const F&, int> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( ! std::regular_invocable<int> );
static_assert( std::regular_invocable<int()> );
static_assert( std::regular_invocable<int(*)()> );
static_assert( std::regular_invocable<int(&)()> );
static_assert( ! std::regular_invocable<int(), int> );
static_assert( ! std::regular_invocable<int() const> );
static_assert( std::regular_invocable<int(const long*, short), long*, char> );
struct A;
static_assert( std::regular_invocable<int A::*, const A&> );
static_assert( ! std::regular_invocable<void (A::*)(long&), const A*, long&> );
static_assert( std::regular_invocable<void (A::*)(long&) const, A*, long&> );
struct F
{
void operator()() const;
void operator()(int);
};
static_assert( std::regular_invocable<F> );
static_assert( std::regular_invocable<F, int> );
static_assert( std::regular_invocable<const F&> );
static_assert( ! std::regular_invocable<const F&, int> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( ! std::relation<bool, void, void> );
static_assert( ! std::relation<bool(), void, void> );
static_assert( ! std::relation<bool(*)(), void, void> );
static_assert( ! std::relation<bool(&)(int, int), void, void> );
static_assert( ! std::relation<bool(), int, int> );
static_assert( ! std::relation<bool() const, int, int> );
static_assert( std::relation<bool(*)(int, int), short, long> );
static_assert( std::relation<bool(&)(const void*, const void*), char[2], int*> );
static_assert( ! std::relation<bool& (const long*, short), long*, char> );
struct A;
static_assert( ! std::relation<int A::*, const A&, const A&> );
static_assert( ! std::relation<void (A::*)(long&), const A*, long&> );
static_assert( ! std::relation<void (A::*)(long&) const, A*, long&> );
static_assert( std::relation<long (A::*)(A*) const, A*, A*> );
struct F
{
void operator()(long, long) const;
bool& operator()(int, const int&) const;
};
static_assert( ! std::relation<F, long, long> );
static_assert( std::relation<F&, int, int> );
static_assert( std::relation<const F&, const int, const int> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( ! std::strict_weak_order<bool, void, void> );
static_assert( ! std::strict_weak_order<bool(), void, void> );
static_assert( ! std::strict_weak_order<bool(*)(), void, void> );
static_assert( ! std::strict_weak_order<bool(&)(int, int), void, void> );
static_assert( ! std::strict_weak_order<bool(), int, int> );
static_assert( ! std::strict_weak_order<bool() const, int, int> );
static_assert( std::strict_weak_order<bool(*)(int, int), short, long> );
static_assert( std::strict_weak_order<bool(&)(const void*, const void*), char[2], int*> );
static_assert( ! std::strict_weak_order<bool& (const long*, short), long*, char> );
struct A;
static_assert( ! std::strict_weak_order<int A::*, const A&, const A&> );
static_assert( ! std::strict_weak_order<void (A::*)(long&), const A*, long&> );
static_assert( ! std::strict_weak_order<void (A::*)(long&) const, A*, long&> );
static_assert( std::strict_weak_order<long (A::*)(A*) const, A*, A*> );
struct F
{
void operator()(long, long) const;
bool& operator()(int, const int&) const;
};
static_assert( ! std::strict_weak_order<F, long, long> );
static_assert( std::strict_weak_order<F&, int, int> );
static_assert( std::strict_weak_order<const F&, const int, const int> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::floating_point<float> );
static_assert( std::floating_point<double> );
static_assert( std::floating_point<long double> );
#ifdef _GLIBCXX_USE_FLOAT128
static_assert( std::floating_point<__float128> );
#endif
static_assert( !std::floating_point<char> );
static_assert( !std::floating_point<signed char> );
static_assert( !std::floating_point<bool> );
static_assert( !std::floating_point<int> );
static_assert( !std::floating_point<char32_t> );
#ifdef __GLIBCXX_TYPE_INT_N_0
static_assert( !std::floating_point<signed __GLIBCXX_TYPE_INT_N_0> );
#endif
static_assert( !std::floating_point<void> );
static_assert( !std::floating_point<float*> );
static_assert( !std::floating_point<float&> );
static_assert( !std::floating_point<float&&> );
static_assert( !std::floating_point<const float&> );
static_assert( !std::floating_point<float[]> );
static_assert( !std::floating_point<float[2]> );
static_assert( !std::floating_point<float()> );
static_assert( !std::floating_point<float(*)()> );
static_assert( !std::floating_point<float(&)()> );
enum E { };
static_assert( !std::floating_point<E> );
enum class CE { };
static_assert( !std::floating_point<CE> );
struct A { };
static_assert( !std::floating_point<A> );
union B { };
static_assert( !std::floating_point<B> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
// signed integer types
static_assert( std::integral<signed char> );
static_assert( std::integral<signed short> );
static_assert( std::integral<signed int> );
static_assert( std::integral<signed long> );
static_assert( std::integral<signed long long> );
// unsigned integer types
static_assert( std::integral<unsigned char> );
static_assert( std::integral<unsigned short> );
static_assert( std::integral<unsigned int> );
static_assert( std::integral<unsigned long> );
static_assert( std::integral<unsigned long long> );
// other integral types
static_assert( std::integral<bool> );
static_assert( std::integral<char> );
static_assert( std::integral<char16_t> );
static_assert( std::integral<char32_t> );
#ifdef _GLIBCXX_USE_WCHAR_T
static_assert( std::integral<wchar_t> );
#endif
#ifdef _GLIBCXX_USE_CHAR8_T
static_assert( std::integral<char8_t> );
#endif
#ifdef __GLIBCXX_TYPE_INT_N_0
static_assert( std::integral<signed __GLIBCXX_TYPE_INT_N_0> );
static_assert( std::integral<unsigned __GLIBCXX_TYPE_INT_N_0> );
#endif
static_assert( !std::integral<void> );
static_assert( !std::integral<float> );
static_assert( !std::integral<int*> );
static_assert( !std::integral<int&> );
static_assert( !std::integral<int&&> );
static_assert( !std::integral<const int&> );
static_assert( !std::integral<int[]> );
static_assert( !std::integral<int[2]> );
static_assert( !std::integral<int()> );
static_assert( !std::integral<int(*)()> );
static_assert( !std::integral<int(&)()> );
enum E { };
static_assert( !std::integral<E> );
enum class CE { };
static_assert( !std::integral<CE> );
struct A { };
static_assert( !std::integral<A> );
union B { };
static_assert( !std::integral<B> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
// signed integer types
static_assert( std::signed_integral<signed char> );
static_assert( std::signed_integral<signed short> );
static_assert( std::signed_integral<signed int> );
static_assert( std::signed_integral<signed long> );
static_assert( std::signed_integral<signed long long> );
// unsigned integer types
static_assert( !std::signed_integral<unsigned char> );
static_assert( !std::signed_integral<unsigned short> );
static_assert( !std::signed_integral<unsigned int> );
static_assert( !std::signed_integral<unsigned long> );
static_assert( !std::signed_integral<unsigned long long> );
// other integral types
static_assert( !std::signed_integral<bool> );
static_assert( std::is_signed_v<char> ? std::signed_integral<char> : true );
static_assert( !std::signed_integral<char16_t> );
static_assert( !std::signed_integral<char32_t> );
#ifdef _GLIBCXX_USE_WCHAR_T
static_assert( std::is_signed_v<wchar_t> ? std::signed_integral<wchar_t> : true );
#endif
#ifdef _GLIBCXX_USE_CHAR8_T
static_assert( !std::signed_integral<char8_t> );
#endif
#ifdef __GLIBCXX_TYPE_INT_N_0
static_assert( std::signed_integral<signed __GLIBCXX_TYPE_INT_N_0> );
static_assert( !std::signed_integral<unsigned __GLIBCXX_TYPE_INT_N_0> );
#endif
static_assert( !std::signed_integral<void> );
static_assert( !std::signed_integral<float> );
static_assert( !std::signed_integral<int&> );
static_assert( !std::signed_integral<int&> );
static_assert( !std::signed_integral<int&&> );
static_assert( !std::signed_integral<const int&> );
static_assert( !std::signed_integral<int[]> );
static_assert( !std::signed_integral<int[2]> );
static_assert( !std::signed_integral<int()> );
static_assert( !std::signed_integral<int(*)()> );
static_assert( !std::signed_integral<int(&)()> );
enum E { };
static_assert( !std::signed_integral<E> );
enum class CE { };
static_assert( !std::signed_integral<CE> );
struct A { };
static_assert( !std::signed_integral<A> );
union B { };
static_assert( !std::signed_integral<B> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
// unsigned integer types
static_assert( std::unsigned_integral<unsigned char> );
static_assert( std::unsigned_integral<unsigned short> );
static_assert( std::unsigned_integral<unsigned int> );
static_assert( std::unsigned_integral<unsigned long> );
static_assert( std::unsigned_integral<unsigned long long> );
// signed integer types
static_assert( !std::unsigned_integral<signed char> );
static_assert( !std::unsigned_integral<signed short> );
static_assert( !std::unsigned_integral<signed int> );
static_assert( !std::unsigned_integral<signed long> );
static_assert( !std::unsigned_integral<signed long long> );
// other integral types
static_assert( std::unsigned_integral<bool> );
static_assert( std::is_signed_v<char> ? true : std::unsigned_integral<char> );
static_assert( std::unsigned_integral<char16_t> );
static_assert( std::unsigned_integral<char32_t> );
#ifdef _GLIBCXX_USE_WCHAR_T
static_assert( std::is_signed_v<wchar_t> ? true : std::unsigned_integral<wchar_t> );
#endif
#ifdef _GLIBCXX_USE_CHAR8_T
static_assert( std::unsigned_integral<char8_t> );
#endif
#ifdef __GLIBCXX_TYPE_INT_N_0
static_assert( !std::unsigned_integral<signed __GLIBCXX_TYPE_INT_N_0> );
static_assert( std::unsigned_integral<unsigned __GLIBCXX_TYPE_INT_N_0> );
#endif
static_assert( !std::unsigned_integral<void> );
static_assert( !std::unsigned_integral<float> );
static_assert( !std::unsigned_integral<unsigned&> );
static_assert( !std::unsigned_integral<unsigned&> );
static_assert( !std::unsigned_integral<unsigned&&> );
static_assert( !std::unsigned_integral<const unsigned&> );
static_assert( !std::unsigned_integral<unsigned[]> );
static_assert( !std::unsigned_integral<unsigned[2]> );
static_assert( !std::unsigned_integral<unsigned()> );
static_assert( !std::unsigned_integral<unsigned(*)()> );
static_assert( !std::unsigned_integral<unsigned(&)()> );
enum E { };
static_assert( !std::unsigned_integral<E> );
enum class CE { };
static_assert( !std::unsigned_integral<CE> );
struct A { };
static_assert( !std::unsigned_integral<A> );
union B { };
static_assert( !std::unsigned_integral<B> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( !std::assignable_from<void, void> );
static_assert( !std::assignable_from<void*, int*> );
static_assert( std::assignable_from<void*&, int*> );
static_assert( !std::assignable_from<void*&, const int*> );
static_assert( std::assignable_from<const void*&, const int*> );
static_assert( !std::assignable_from<char, char> );
static_assert( std::assignable_from<char&, char> );
static_assert( !std::assignable_from<float, float> );
static_assert( std::assignable_from<float&, double> );
static_assert( std::assignable_from<int*&, int*> );
static_assert( std::assignable_from<int&, int&> );
static_assert( std::assignable_from<int&, int&&> );
static_assert( !std::assignable_from<int&&, int> );
static_assert( !std::assignable_from<const int&, int> );
static_assert( !std::assignable_from<const int&, int&> );
static_assert( !std::assignable_from<const int&, const int> );
static_assert( !std::assignable_from<const int&, const int&> );
static_assert( !std::assignable_from<int(&)[], int(&)[]> );
static_assert( !std::assignable_from<int(&)[], int> );
static_assert( !std::assignable_from<int(&)[2], int(&)[2]> );
static_assert( !std::assignable_from<int(), int()> );
static_assert( !std::assignable_from<int(*)(), int(*)()> );
static_assert( std::assignable_from<int(*&)(), int(*)()> );
static_assert( std::assignable_from<int(*&)(), std::nullptr_t> );
static_assert( std::assignable_from<int(*&)(), int(*)() noexcept> );
static_assert( std::assignable_from<int(*&)(), int(&)() noexcept> );
static_assert( !std::assignable_from<int(&)(), std::nullptr_t> );
static_assert( !std::assignable_from<int(&)(), int(&)() noexcept> );
enum E { };
static_assert( !std::assignable_from<E, E> );
static_assert( std::assignable_from<E&, E> );
static_assert( std::assignable_from<E&, E&> );
static_assert( std::assignable_from<E&, const E&> );
static_assert( !std::assignable_from<const E&, const E&> );
enum class CE { };
static_assert( !std::assignable_from<CE, CE> );
static_assert( std::assignable_from<CE&, CE&> );
static_assert( std::assignable_from<CE&, const CE&> );
static_assert( !std::assignable_from<const CE&, const CE&> );
struct A { };
static_assert( !std::assignable_from<A, A> );
static_assert( std::assignable_from<A&, A> );
static_assert( !std::assignable_from<A, A&> );
static_assert( std::assignable_from<A&, const A&> );
union B { };
static_assert( !std::assignable_from<B, B> );
static_assert( std::assignable_from<B&, B> );
static_assert( !std::assignable_from<B, B&> );
static_assert( std::assignable_from<B&, const B&> );
struct C
{
C(int) { }
C& operator=(const C&) { return *this; }
C& operator=(int) { return *this; }
void operator=(void*) { }
};
static_assert( std::assignable_from<C&, C> );
static_assert( std::assignable_from<C&, const C&> );
static_assert( std::assignable_from<C&, int> );
static_assert( !std::assignable_from<C&, void*> );
static_assert( !std::assignable_from<C&, std::nullptr_t> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::common_with<int, int> );
static_assert( std::common_with<int, const int> );
static_assert( std::common_with<int&&, const int&> );
static_assert( std::common_with<int&, const int&&> );
static_assert( std::common_with<void, void> );
static_assert( ! std::common_with<int, void> );
static_assert( ! std::common_with<int, int*> );
static_assert( ! std::common_with<int, int()> );
static_assert( std::common_with<int, short> );
static_assert( std::common_with<short, int> );
static_assert( std::common_with<void*, const int*> );
struct A { A(int) { } };
static_assert( std::common_with<A, int> );
struct B { };
static_assert( ! std::common_with<A, B> );
struct C { C(const A&) { } };
static_assert( std::common_with<A, C> );
static_assert( std::common_with<A, const C> );
static_assert( std::common_with<const A, C> );
static_assert( std::common_with<const A, const C> );
struct D;
struct E { E(const D&) { } };
struct D { D(const E&) { } };
static_assert( ! std::common_with<D, E> ); // ambiguous conversion
struct F { };
struct G { };
struct H {
H(const F&) { }
H(const G&) { }
};
namespace std
{
template<> struct common_type<F, G> { using type = H; };
template<> struct common_type<G, F> { using type = H; };
}
static_assert( std::common_with<F, G> );
static_assert( std::common_with<F, const G> );
static_assert( std::common_with<const F, G> );
static_assert( std::common_with<const F, const G> );
struct Base { };
struct Derived : Base { };
static_assert( std::common_with<Derived, Base> );
static_assert( std::common_with<Derived*, Base*> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::common_reference_with<int, int> );
static_assert( std::common_reference_with<int, const int> );
static_assert( std::common_reference_with<int&&, const int&> );
static_assert( std::common_reference_with<int&, const int&&> );
static_assert( ! std::common_reference_with<int, void> );
static_assert( ! std::common_reference_with<int, int*> );
static_assert( ! std::common_reference_with<int, int()> );
struct A { A(int) { } };
static_assert( std::common_reference_with<A, int> );
struct B { };
static_assert( ! std::common_reference_with<A, B> );
struct C { C(A&) { } };
static_assert( std::common_reference_with<A&, C> );
static_assert( std::common_reference_with<A&, C&&> );
static_assert( std::common_reference_with<A&, const C&> );
static_assert( std::common_reference_with<A&, C&> );
static_assert( ! std::common_reference_with<const A&, C> );
static_assert( ! std::common_reference_with<const A&, const C&> );
struct D;
struct E { E(D&) { } };
struct D { D(E&) { } };
static_assert( ! std::common_reference_with<D&, E&> ); // ambiguous conversion
struct F;
struct G { G(const F&) { } };
struct F { F(const G&) { } };
namespace std
{
template<template<typename> class Qual1, template<typename> class Qual2>
struct basic_common_reference<F, G, Qual1, Qual2>
{ using type = Qual1<Qual2<F>>; };
template<template<typename> class Qual1, template<typename> class Qual2>
struct basic_common_reference<G, F, Qual1, Qual2>
{ using type = Qual1<Qual2<F>>; };
}
static_assert( ! std::common_reference_with<F&, G&> );
static_assert( std::common_reference_with<F, G> );
static_assert( std::common_reference_with<F, const G> );
static_assert( std::common_reference_with<const F, const G> );
struct Base { };
struct Derived : Base { };
static_assert( std::common_reference_with<Derived&, Base&> );
static_assert( std::common_with<Derived*, Base*> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( !std::constructible_from<void> );
static_assert( !std::constructible_from<void, void> );
static_assert( std::constructible_from<void*, int*> );
static_assert( !std::constructible_from<void*, const int*> );
static_assert( std::constructible_from<const void*, const int*> );
static_assert( std::constructible_from<char> );
static_assert( std::constructible_from<float> );
static_assert( std::constructible_from<float, float> );
static_assert( std::constructible_from<float, double> );
static_assert( std::constructible_from<int*> );
static_assert( std::constructible_from<int*, int*> );
static_assert( !std::constructible_from<int&> );
static_assert( std::constructible_from<int&, int&> );
static_assert( !std::constructible_from<int&&> );
static_assert( std::constructible_from<int&&, int> );
static_assert( !std::constructible_from<const int&> );
static_assert( std::constructible_from<const int&, int> );
static_assert( std::constructible_from<const int&, int&> );
static_assert( std::constructible_from<const int&, const int> );
static_assert( std::constructible_from<const int&, const int&> );
static_assert( !std::constructible_from<const int&, int, int> );
static_assert( !std::constructible_from<int[]> );
static_assert( std::constructible_from<int[2]> );
static_assert( !std::constructible_from<int()> );
static_assert( std::constructible_from<int(*)()> );
static_assert( std::constructible_from<int(*)(), std::nullptr_t> );
static_assert( std::constructible_from<int(*)(), int(*)() noexcept> );
static_assert( std::constructible_from<int(*)(), int(&)() noexcept> );
static_assert( !std::constructible_from<int(&)()> );
static_assert( std::constructible_from<int(&)(), int(&)() noexcept> );
enum E { };
static_assert( std::constructible_from<E> );
static_assert( std::constructible_from<E, E&> );
enum class CE { };
static_assert( std::constructible_from<CE> );
static_assert( std::constructible_from<CE, CE&> );
struct A { };
static_assert( std::constructible_from<A> );
static_assert( std::constructible_from<A, A> );
static_assert( std::constructible_from<A, A&> );
static_assert( std::constructible_from<A, const A&> );
union B { };
static_assert( std::constructible_from<B> );
static_assert( std::constructible_from<B, B> );
static_assert( std::constructible_from<B, B&> );
static_assert( std::constructible_from<B, const B&> );
struct C
{
C(void* = nullptr) { }
~C() noexcept(false) { }
};
static_assert( !std::constructible_from<C> );
static_assert( !std::constructible_from<C, void*> );
static_assert( !std::constructible_from<C, std::nullptr_t> );
class D
{
public:
D() { }
D(int) { }
private:
~D() { }
};
static_assert( !std::constructible_from<D> );
static_assert( !std::constructible_from<D, int> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::convertible_to<int, int> );
static_assert( std::convertible_to<int&, int> );
static_assert( !std::convertible_to<int, int&> );
static_assert( std::convertible_to<int, const int&> );
static_assert( !std::convertible_to<int&&, int&> );
static_assert( std::convertible_to<int&&, const int&> );
static_assert( std::convertible_to<const int, int> );
static_assert( !std::convertible_to<const int, int&> );
static_assert( std::convertible_to<const int, const int> );
static_assert( std::convertible_to<const int, const int&> );
static_assert( std::convertible_to<int, float> );
static_assert( !std::convertible_to<int, float&> );
static_assert( !std::convertible_to<int, int*> );
static_assert( std::convertible_to<int*, void*> );
static_assert( std::convertible_to<int*, const void*> );
static_assert( !std::convertible_to<const int*, void*> );
static_assert( !std::convertible_to<int, void> );
struct A { };
static_assert( std::convertible_to<A, A> );
static_assert( std::convertible_to<A, const A> );
static_assert( std::convertible_to<A const, const A> );
static_assert( !std::convertible_to<volatile A, const A> );
static_assert( !std::convertible_to<volatile A, const volatile A&> );
static_assert( std::convertible_to<volatile A&, const volatile A&> );
struct B : A { };
static_assert( !std::convertible_to<A, B> );
static_assert( std::convertible_to<B, A> );
static_assert( std::convertible_to<const B, A> );
static_assert( std::convertible_to<B, const A> );
static_assert( std::convertible_to<B, const A&> );
static_assert( !std::convertible_to<volatile B, const A> );
static_assert( !std::convertible_to<volatile B, const A&> );
struct C : private A { };
static_assert( !std::convertible_to<A, C> );
static_assert( !std::convertible_to<C, A> );
struct D : A { };
struct E : B, D { };
static_assert( !std::convertible_to<A, E> );
static_assert( !std::convertible_to<E, A> );
struct F
{
F(A) { }
F(C&&) { }
};
static_assert( std::convertible_to<A, F> );
static_assert( std::convertible_to<const A, F> );
static_assert( std::convertible_to<C, F> );
static_assert( !std::convertible_to<C&, F> );
static_assert( !std::convertible_to<const C, F> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( !std::copy_constructible<void> );
static_assert( std::copy_constructible<void*> );
static_assert( std::copy_constructible<const void*> );
static_assert( std::copy_constructible<char> );
static_assert( std::copy_constructible<const float> );
static_assert( std::copy_constructible<int*> );
static_assert( std::copy_constructible<int&> );
static_assert( !std::copy_constructible<int&&> );
static_assert( std::copy_constructible<const int&> );
static_assert( !std::copy_constructible<int[]> );
static_assert( !std::copy_constructible<int[2]> );
static_assert( !std::copy_constructible<int()> );
static_assert( std::copy_constructible<int(*)()> );
static_assert( std::copy_constructible<int(&)()> );
static_assert( std::copy_constructible<int(&)() noexcept> );
enum E { };
static_assert( std::copy_constructible<E> );
enum class CE { };
static_assert( std::copy_constructible<CE> );
struct A { };
static_assert( std::copy_constructible<A> );
union B { };
static_assert( std::copy_constructible<B> );
struct C
{
C(void* = nullptr) { }
~C() noexcept(false) { }
};
static_assert( !std::copy_constructible<C> );
class D
{
public:
D() { }
D(int) { }
private:
~D() { }
};
static_assert( !std::copy_constructible<D> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( !std::default_constructible<void> );
static_assert( std::default_constructible<void*> );
static_assert( std::default_constructible<const void*> );
static_assert( std::default_constructible<char> );
static_assert( std::default_constructible<float> );
static_assert( std::default_constructible<const int> );
static_assert( std::default_constructible<int*> );
static_assert( !std::default_constructible<int&> );
static_assert( !std::default_constructible<int&&> );
static_assert( !std::default_constructible<const int&> );
static_assert( !std::default_constructible<int[]> );
static_assert( std::default_constructible<int[2]> );
static_assert( !std::default_constructible<int()> );
static_assert( std::default_constructible<int(*)()> );
static_assert( !std::default_constructible<int(&)()> );
enum E { };
static_assert( std::default_constructible<E> );
enum class CE { };
static_assert( std::default_constructible<CE> );
struct A { };
static_assert( std::default_constructible<A> );
union B { };
static_assert( std::constructible_from<B> );
struct C
{
C(void* = nullptr) { }
~C() noexcept(false) { }
};
static_assert( !std::default_constructible<C> );
class D
{
public:
D() { }
D(int) { }
private:
~D() { }
};
static_assert( !std::default_constructible<D> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( !std::derived_from<int, int> );
static_assert( !std::derived_from<int&, int> );
static_assert( !std::derived_from<int, int&> );
static_assert( !std::derived_from<int&&, int&> );
static_assert( !std::derived_from<const int, int> );
static_assert( !std::derived_from<const int, const int> );
struct A { };
static_assert( std::derived_from<A, A> );
static_assert( std::derived_from<A, const A> );
static_assert( std::derived_from<A const, const A> );
static_assert( std::derived_from<volatile A, const A> );
struct B : A { };
static_assert( !std::derived_from<A, B> );
static_assert( std::derived_from<B, A> );
static_assert( std::derived_from<const B, A> );
static_assert( std::derived_from<B, const A> );
static_assert( std::derived_from<volatile B, const A> );
struct C : private A { };
static_assert( !std::derived_from<A, C> );
static_assert( !std::derived_from<C, A> );
struct D : A { };
struct E : B, D { };
static_assert( !std::derived_from<A, E> );
static_assert( !std::derived_from<E, A> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( !std::destructible<void> );
static_assert( std::destructible<char> );
static_assert( std::destructible<float> );
static_assert( std::destructible<int*> );
static_assert( std::destructible<int&> );
static_assert( std::destructible<int&&> );
static_assert( std::destructible<const int&> );
static_assert( !std::destructible<int[]> );
static_assert( std::destructible<int[2]> );
static_assert( !std::destructible<int()> );
static_assert( std::destructible<int(*)()> );
static_assert( std::destructible<int(&)()> );
enum E { };
static_assert( std::destructible<E> );
enum class CE { };
static_assert( std::destructible<CE> );
struct A { };
static_assert( std::destructible<A> );
union B { };
static_assert( std::destructible<B> );
struct C
{
~C() noexcept(false) { }
};
static_assert( !std::destructible<C> );
class D
{
public:
D() { }
private:
~D() { }
};
static_assert( !std::destructible<D> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( !std::move_constructible<void> );
static_assert( std::move_constructible<void*> );
static_assert( std::move_constructible<const void*> );
static_assert( std::move_constructible<char> );
static_assert( std::move_constructible<const float> );
static_assert( std::move_constructible<int*> );
static_assert( std::move_constructible<int&> );
static_assert( std::move_constructible<int&&> );
static_assert( std::move_constructible<const int&> );
static_assert( !std::move_constructible<int[]> );
static_assert( !std::move_constructible<int[2]> );
static_assert( !std::move_constructible<int()> );
static_assert( std::move_constructible<int(*)()> );
static_assert( std::move_constructible<int(&)()> );
static_assert( std::move_constructible<int(&)() noexcept> );
enum E { };
static_assert( std::move_constructible<E> );
enum class CE { };
static_assert( std::move_constructible<CE> );
struct A { };
static_assert( std::move_constructible<A> );
union B { };
static_assert( std::move_constructible<B> );
struct C
{
C(void* = nullptr) { }
~C() noexcept(false) { }
};
static_assert( !std::move_constructible<C> );
class D
{
public:
D() { }
D(int) { }
private:
~D() { }
};
static_assert( !std::move_constructible<D> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::same_as<int, int> );
static_assert( !std::same_as<int&, int> );
static_assert( !std::same_as<int, int&> );
static_assert( !std::same_as<int&&, int&> );
static_assert( !std::same_as<const int, int> );
static_assert( std::same_as<const int, const int> );
struct A { };
static_assert( std::same_as<A, A> );
static_assert( !std::same_as<A, const A> );
static_assert( std::same_as<A const, const A> );
static_assert( !std::same_as<volatile A, const A> );
struct B : A { };
static_assert( !std::same_as<A, B> );
template<typename T, typename U>
constexpr int
check_subsumption()
{ return 0; }
template<typename T, typename U>
requires std::same_as<T, U>
constexpr int
check_subsumption()
{ return 1; }
template<typename T, typename U>
requires std::same_as<U, T> && std::is_const_v<T>
constexpr int
check_subsumption()
{ return 2; }
template<typename T, typename U>
requires std::same_as<U, T> && std::is_volatile_v<T>
constexpr int
check_subsumption()
{ return 3; }
static_assert( check_subsumption<short, long>() == 0 );
static_assert( check_subsumption<unsigned, unsigned>() == 1 );
// These will be ambiguous if same_as<T,U> doesn't subsume same_as<U,T>:
static_assert( check_subsumption<const char, const char>() == 2 );
static_assert( check_subsumption<volatile int, volatile int>() == 3 );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
namespace nu
{
struct S { bool swapped = false; };
constexpr void swap(S& l, S& r) { l.swapped = r.swapped = true; }
struct T { int i; };
union U { char c; int i; };
constexpr void swap(U& l, U& r) { l.i = r.i = 99; }
}
constexpr bool check_struct_with_adl_swap(int i)
{
nu::S s1, s2;
std::ranges::swap(s1, s2);
return s1.swapped && s2.swapped;
}
static_assert(check_struct_with_adl_swap(1));
constexpr bool check_array_with_adl_swap(int i)
{
nu::S s1[2], s2[2];
std::ranges::swap(s1, s2);
return s1[0].swapped && s2[0].swapped && s1[1].swapped && s2[1].swapped;
}
static_assert(check_array_with_adl_swap(1));
constexpr bool check_struct_without_adl_swap(int i)
{
nu::T t1{i}, t2{2*i};
std::ranges::swap(t1, t2);
return t1.i == 2*i && t2.i == i;
}
static_assert(check_struct_without_adl_swap(1));
constexpr bool check_array_without_adl_swap(int i)
{
nu::T t1[2]{i, 2*i}, t2[2]{3*i, 4*i};
std::ranges::swap(t1, t2);
return t1[0].i == 3*i && t2[0].i == i && t1[1].i == 4*i && t2[1].i == 2*i;
}
static_assert(check_array_without_adl_swap(1));
constexpr bool check_union_with_adl_swap(int i)
{
nu::U u1{}, u2{};
u1.i = u2.i = i;
std::ranges::swap(u1, u2);
return u1.i == 99 && u2.i == 99;
}
static_assert(check_union_with_adl_swap(1));
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
namespace nu
{
struct S { bool swapped = false; };
constexpr void swap(S& l, S& r) { }
struct T { int i; };
union U { char c; int i; };
constexpr void swap(U& l, U& r) { }
}
static_assert( std::swappable<nu::S> );
static_assert( !std::swappable<const nu::S> );
static_assert( std::swappable<nu::T> );
static_assert( !std::swappable<const nu::T> );
static_assert( std::swappable<nu::U> );
static_assert( !std::swappable<const nu::U> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::swappable_with<int&, int&> );
static_assert( ! std::swappable_with<int, int> );
static_assert( ! std::swappable_with<int*, int*> );
static_assert( ! std::swappable_with<int&, const int&> );
static_assert( ! std::swappable_with<const int&, const int&> );
static_assert( ! std::swappable_with<int&, long&> );
namespace N1
{
struct Immovable
{
Immovable() = default;
Immovable(Immovable&&) = delete;
};
}
static_assert( ! std::swappable_with<N1::Immovable&, N1::Immovable&> );
namespace N2
{
struct Swappable
{
Swappable() = default;
Swappable(Swappable&&) = delete;
friend void swap(Swappable&, Swappable&) { }
};
}
static_assert( std::swappable_with<N2::Swappable&, N2::Swappable&> );
namespace N3
{
struct A { };
struct Proxy {
Proxy(A&) { }
friend void swap(Proxy, Proxy) { }
};
}
static_assert( std::swappable_with<N3::A&, N3::A&> );
static_assert( std::swappable_with<N3::A&, N3::Proxy> );
static_assert( std::swappable_with<N3::Proxy, N3::A&> );
static_assert( std::swappable_with<N3::Proxy, N3::Proxy> );
struct C { C(int&) { } };
void swap(int&, C&) { } // not symmetrical
static_assert( ! std::swappable_with<int, C> );
static_assert( ! std::swappable_with<C, int> );
struct D { D(int&) { } };
void swap(int&, D&) { }
void swap(D&&, int&) { } // only accepts rvalues
static_assert( ! std::swappable_with<int&, D> );
static_assert( ! std::swappable_with<D, int> );
struct E { E(int&) { } };
void swap(int, E&&) { } // only accepts rvalues
void swap(E&, int) { }
static_assert( ! std::swappable_with<int, E> );
static_assert( ! std::swappable_with<E, int> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::copyable<int> );
static_assert( std::copyable<int*> );
static_assert( ! std::copyable<int&> );
static_assert( ! std::copyable<void> );
static_assert( ! std::copyable<void()> );
static_assert( ! std::copyable<void() noexcept> );
static_assert( ! std::copyable<void() const> );
struct Trivial { };
static_assert( std::copyable<Trivial> );
struct NotTrivial
{
NotTrivial(int) { }
NotTrivial(const NotTrivial&) { }
NotTrivial& operator=(const NotTrivial&) { return *this; }
~NotTrivial() { }
};
static_assert( std::copyable<NotTrivial> );
namespace N1
{
struct Immovable
{
Immovable() = default;
Immovable(Immovable&&) = delete;
};
}
static_assert( ! std::copyable<N1::Immovable> );
struct Movable
{
Movable() = default;
Movable(Movable&&) = default;
Movable& operator=(Movable&&) = default;
};
static_assert( ! std::copyable<Movable> );
struct MovableAndCopyAssignable
{
MovableAndCopyAssignable() = default;
MovableAndCopyAssignable(MovableAndCopyAssignable&&) = default;
MovableAndCopyAssignable& operator=(MovableAndCopyAssignable&&) = default;
MovableAndCopyAssignable& operator=(const MovableAndCopyAssignable&) = default;
};
static_assert( ! std::copyable<MovableAndCopyAssignable> );
struct MovableAndCopyConstructible
{
MovableAndCopyConstructible() = default;
MovableAndCopyConstructible(MovableAndCopyConstructible&&) = default;
MovableAndCopyConstructible(const MovableAndCopyConstructible&) = default;
MovableAndCopyConstructible& operator=(MovableAndCopyConstructible&&) = default;
};
static_assert( ! std::copyable<MovableAndCopyConstructible> );
namespace N2
{
struct Swappable
{
Swappable() = default;
Swappable(Swappable&&) = default;
friend void swap(Swappable&, Swappable&) { }
};
}
static_assert( ! std::copyable<N2::Swappable> );
struct NotAssignable
{
NotAssignable() = default;
NotAssignable(NotAssignable&&) = default;
NotAssignable& operator=(NotAssignable&&) = default;
NotAssignable(const NotAssignable&) = default;
NotAssignable& operator=(const NotAssignable&) = delete;
friend void swap(NotAssignable&, NotAssignable&) { }
};
static_assert( ! std::copyable<NotAssignable> );
struct NotSwappable
{
NotSwappable() = default;
NotSwappable(const NotSwappable&) = default;
NotSwappable& operator=(const NotSwappable&) = default;
};
void swap(NotSwappable&, NotSwappable&) = delete;
static_assert( std::copyable<NotSwappable> ); // ranges::swap still works!
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::movable<int> );
static_assert( std::movable<int*> );
static_assert( ! std::movable<int&> );
static_assert( ! std::movable<void> );
static_assert( ! std::movable<void()> );
static_assert( ! std::movable<void() noexcept> );
static_assert( ! std::movable<void() const> );
struct Trivial { };
static_assert( std::movable<Trivial> );
struct NotTrivial
{
NotTrivial(int) { }
NotTrivial(NotTrivial&&) { }
NotTrivial& operator=(NotTrivial&&) { return *this; }
~NotTrivial() { }
};
static_assert( std::movable<NotTrivial> );
namespace N1
{
struct Immovable
{
Immovable() = default;
Immovable(Immovable&&) = delete;
};
}
static_assert( ! std::movable<N1::Immovable> );
namespace N2
{
struct Swappable
{
Swappable() = default;
Swappable(Swappable&&) = delete;
Swappable& operator=(Swappable&&) = default;
friend void swap(Swappable&, Swappable&) { }
};
}
static_assert( ! std::movable<N2::Swappable> );
struct NotAssignable
{
NotAssignable() = default;
NotAssignable(NotAssignable&&) = default;
NotAssignable& operator=(NotAssignable&&) = delete;
friend void swap(NotAssignable&, NotAssignable&) { }
};
static_assert( ! std::movable<NotAssignable> );
struct NotSwappable
{
NotSwappable() = default;
NotSwappable(NotSwappable&&) = default;
NotSwappable& operator=(NotSwappable&&) = default;
};
void swap(NotSwappable&, NotSwappable&) = delete;
static_assert( std::movable<NotSwappable> ); // ranges::swap still works!
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::regular<int> );
static_assert( std::regular<int*> );
static_assert( ! std::regular<int&> );
static_assert( ! std::regular<void> );
static_assert( ! std::regular<void()> );
static_assert( ! std::regular<void() noexcept> );
static_assert( ! std::regular<void() const> );
struct Trivial { };
static_assert( ! std::regular<Trivial> );
struct NotTrivial
{
NotTrivial() { }
~NotTrivial() { }
};
static_assert( ! std::regular<NotTrivial> );
struct NotDefaultConstructible
{
NotDefaultConstructible(int) { }
};
static_assert( ! std::regular<NotDefaultConstructible> );
struct HasReference
{
int& ref;
};
static_assert( ! std::regular<HasReference> );
struct HasEq { };
bool operator==(HasEq, HasEq) { return true; }
#ifdef __cpp_lib_three_way_comparison
static_assert( std::regular<HasEq> );
#else
static_assert( ! std::regular<HasEq> );
#endif
struct HasEqNeq { };
bool operator==(HasEqNeq, HasEqNeq) { return true; }
bool operator!=(HasEqNeq, HasEqNeq) { return false; }
static_assert( std::regular<HasEqNeq> );
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-options "-std=gnu++2a" }
// { dg-do compile { target c++2a } }
#include <concepts>
static_assert( std::semiregular<int> );
static_assert( std::semiregular<int*> );
static_assert( ! std::semiregular<int&> );
static_assert( ! std::semiregular<void> );
static_assert( ! std::semiregular<void()> );
static_assert( ! std::semiregular<void() noexcept> );
static_assert( ! std::semiregular<void() const> );
struct Trivial { };
static_assert( std::semiregular<Trivial> );
struct NotTrivial
{
NotTrivial() { }
~NotTrivial() { }
};
static_assert( std::semiregular<NotTrivial> );
struct NotDefaultConstructible
{
NotDefaultConstructible(int) { }
};
static_assert( ! std::semiregular<NotDefaultConstructible> );
struct HasReference
{
int& ref;
};
static_assert( ! std::semiregular<HasReference> );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment