Index: libcxx/CREDITS.TXT =================================================================== --- libcxx/CREDITS.TXT +++ libcxx/CREDITS.TXT @@ -41,6 +41,11 @@ E: jbcoe@me.com D: Implementation of propagate_const. +N: Christopher Di Bella +E: cjdb@google.com +E: cjdb.ns@gmail.com +D: Library concepts. + N: Glen Joseph Fernandes E: glenjofe@gmail.com D: Implementation of to_address. Index: libcxx/include/CMakeLists.txt =================================================================== --- libcxx/include/CMakeLists.txt +++ libcxx/include/CMakeLists.txt @@ -45,6 +45,7 @@ compare complex complex.h + concepts condition_variable csetjmp csignal Index: libcxx/include/concepts =================================================================== --- /dev/null +++ libcxx/include/concepts @@ -0,0 +1,166 @@ +// -*- C++ -*- +//===-------------------------- concepts ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONCEPTS +#define _LIBCPP_CONCEPTS + +/* + concepts synopsis +namespace std { + // [concepts.lang], language-related concepts + // [concept.same], concept same_as + template + concept same_as = see below; + + // [concept.derived], concept derived_from + template + concept derived_from = see below; + + // [concept.convertible], concept convertible_to + template + concept convertible_to = see below; + + // [concept.commonref], concept common_reference_with + template + concept common_reference_with = see below; + + // [concept.common], concept common_with + template + concept common_with = see below; + + // [concepts.arithmetic], arithmetic concepts + template + concept integral = see below; + template + concept signed_integral = see below; + template + concept unsigned_integral = see below; + template + concept floating_point = see below; + + // [concept.assignable], concept assignable_from + template + concept assignable_from = see below; + + // [concept.swappable], concept swappable + namespace ranges { + inline namespace unspecified { + inline constexpr unspecified swap = unspecified; + } + } + template + concept swappable = see below; + template + concept swappable_with = see below; + + // [concept.destructible], concept destructible + template + concept destructible = see below; + + // [concept.constructible], concept constructible_from + template + concept constructible_from = see below; + + // [concept.defaultconstructible], concept default_constructible + template + concept default_constructible = see below; + + // [concept.moveconstructible], concept move_constructible + template + concept move_constructible = see below; + + // [concept.copyconstructible], concept copy_constructible + template + concept copy_constructible = see below; + + // [concepts.compare], comparison concepts + // [concept.boolean], concept boolean + template + concept boolean = see below; + + // [concept.equalitycomparable], concept equality_comparable + template + concept equality_comparable = see below; + template + concept equality_comparable_with = see below; + + // [concept.totallyordered], concept totally_ordered + template + concept totally_ordered = see below; + template + concept totally_ordered_with = see below; + + // [concepts.object], object concepts + template + concept movable = see below; + template + concept copyable = see below; + template + concept semiregular = see below; + template + concept regular = see below; + + // [concepts.callable], callable concepts + // [concept.invocable], concept invocable + template + concept invocable = see below; + + // [concept.regularinvocable], concept regular_invocable + template + concept regular_invocable = see below; + + // [concept.predicate], concept predicate + template + concept predicate = see below; + + // [concept.relation], concept relation + template + concept relation = see below; + + // [concept.equiv], concept equivalence_relation + template + concept equivalence_relation = see below; + + // [concept.strictweakorder], concept strict_weak_order + template + concept strict_weak_order = see below; +} + +*/ + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L + +// [concept.same] + +template +concept __same_as_impl = _VSTD::_IsSame<_Tp, _Up>::value; + +template +concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>; + +#endif //_LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_CONCEPTS Index: libcxx/include/module.modulemap =================================================================== --- libcxx/include/module.modulemap +++ libcxx/include/module.modulemap @@ -267,6 +267,10 @@ header "complex" export * } + module concepts { + header "concepts" + export * + } module condition_variable { header "condition_variable" export * Index: libcxx/test/libcxx/double_include.sh.cpp =================================================================== --- libcxx/test/libcxx/double_include.sh.cpp +++ libcxx/test/libcxx/double_include.sh.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include Index: libcxx/test/std/concepts/lang/same_as.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/concepts/lang/same_as.pass.cpp @@ -0,0 +1,295 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// template +// concept same_as; + +#include +#include + +struct S1 {}; +struct S2 { + int i; + + int& f(); + double g(int x) const; +}; +struct S3 { + int& r; +}; +struct S4 { + int&& r; +}; +struct S5 { + int* p; +}; + +class C1 {}; +class C2 { + [[maybe_unused]] int i; +}; + +class C3 { +public: + int i; +}; + +template +class C4 { + int t1; + int t2; +}; + +template +class C5 { + [[maybe_unused]] T1 t1; + +public: + T2 t2; +}; + +template +class C6 { +public: + [[maybe_unused]] T1 t1; + [[maybe_unused]] T2 t2; +}; + +template +struct identity { + using type = T; +}; + +template