diff --git a/libcxx/include/concepts b/libcxx/include/concepts --- a/libcxx/include/concepts +++ b/libcxx/include/concepts @@ -173,6 +173,13 @@ static_cast<_To>(__f()); }; +// [concept.commonreference] +template +concept common_reference_with = + same_as, common_reference_t<_Up, _Tp>> && + convertible_to<_Tp, common_reference_t<_Tp, _Up>> && + convertible_to<_Up, common_reference_t<_Up, _Tp>>; + // [concepts.arithmetic], arithmetic concepts template concept integral = is_integral_v<_Tp>; diff --git a/libcxx/test/std/concepts/lang/commonreference.compile.pass.cpp b/libcxx/test/std/concepts/lang/commonreference.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/concepts/lang/commonreference.compile.pass.cpp @@ -0,0 +1,343 @@ +//===----------------------------------------------------------------------===// +// +// 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++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept common_reference_with; + +#include + +template +constexpr bool CheckCommonReferenceWith() noexcept { + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert(std::common_reference_with); + static_assert( + std::common_reference_with); + + return std::common_reference_with; +} + +namespace BuiltinTypes { +// fundamental types +static_assert(std::common_reference_with); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); + +// arrays +static_assert(CheckCommonReferenceWith()); + +// pointers (common with void*) +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert( + CheckCommonReferenceWith()); + +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +struct S {}; +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert( + CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert( + CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); +static_assert(CheckCommonReferenceWith()); + +// nonsense +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +} // namespace BuiltinTypes + +namespace NoDefaultCommonReference { +class T {}; + +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert(!std::common_reference_with); +static_assert( + !std::common_reference_with); +} // namespace NoDefaultCommonReference + +struct BadBasicCommonReference { + // This test is ill-formed, NDR. If it ever blows up in our faces: that's a good thing. + // In the meantime, the test should be included. If compiler support is added, then an include guard + // should be placed so the test doesn't get deleted. + operator int() const; + operator int&(); +}; +static_assert(std::convertible_to); +static_assert(std::convertible_to); + +namespace std { +template