This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement concept emulation for C++14 / C++17
This also ports all the standard concepts from libc++ preserving the new modular organization.
- Loading branch information
Showing
73 changed files
with
12,479 additions
and
1 deletion.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...s/test/std/concepts/concepts.callable/concept.equiv/equivalence_relation.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
|
||
// template<class F, class... Args> | ||
// concept equivalence_relation; | ||
|
||
#include <cuda/std/concepts> | ||
|
||
using cuda::std::equivalence_relation; | ||
|
||
static_assert(equivalence_relation<bool(int, int), int, int>); | ||
static_assert(equivalence_relation<bool(int, int), double, double>); | ||
static_assert(equivalence_relation<bool(int, double), double, double>); | ||
|
||
static_assert(!equivalence_relation<bool (*)(), int, double>); | ||
static_assert(!equivalence_relation<bool (*)(int), int, double>); | ||
static_assert(!equivalence_relation<bool (*)(double), int, double>); | ||
|
||
static_assert( | ||
!equivalence_relation<bool(double, double*), double, double*>); | ||
static_assert(!equivalence_relation<bool(int&, int&), double&, double&>); | ||
|
||
struct S1 {}; | ||
static_assert(cuda::std::relation<bool (S1::*)(S1*), S1*, S1*>); | ||
static_assert(cuda::std::relation<bool (S1::*)(S1&), S1&, S1&>); | ||
|
||
struct S2 {}; | ||
|
||
struct P1 { | ||
bool operator()(S1, S1) const; | ||
}; | ||
static_assert(equivalence_relation<P1, S1, S1>); | ||
|
||
struct P2 { | ||
bool operator()(S1, S1) const; | ||
bool operator()(S1, S2) const; | ||
}; | ||
static_assert(!equivalence_relation<P2, S1, S2>); | ||
|
||
struct P3 { | ||
bool operator()(S1, S1) const; | ||
bool operator()(S1, S2) const; | ||
bool operator()(S2, S1) const; | ||
}; | ||
static_assert(!equivalence_relation<P3, S1, S2>); | ||
|
||
struct P4 { | ||
bool operator()(S1, S1) const; | ||
bool operator()(S1, S2) const; | ||
bool operator()(S2, S1) const; | ||
bool operator()(S2, S2) const; | ||
}; | ||
static_assert(equivalence_relation<P4, S1, S2>); | ||
|
||
int main(int, char**) { return 0; } |
80 changes: 80 additions & 0 deletions
80
...oncepts/concepts.callable/concept.equiv/equivalence_relation.subsumption.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
|
||
// template<class F, class... Args> | ||
// concept equivalence_relation; | ||
|
||
#include <cuda/std/concepts> | ||
|
||
struct S1 {}; | ||
struct S2 {}; | ||
|
||
struct R { | ||
bool operator()(S1, S1) const; | ||
bool operator()(S1, S2) const; | ||
bool operator()(S2, S1) const; | ||
bool operator()(S2, S2) const; | ||
}; | ||
|
||
// clang-format off | ||
template<class F, class T, class U> | ||
requires cuda::std::relation<F, T, U> | ||
constexpr bool check_equivalence_relation_subsumes_relation() { | ||
return false; | ||
} | ||
|
||
template<class F, class T, class U> | ||
requires cuda::std::equivalence_relation<F, T, U> && true | ||
constexpr bool check_equivalence_relation_subsumes_relation() { | ||
return true; | ||
} | ||
// clang-format on | ||
|
||
static_assert(check_equivalence_relation_subsumes_relation<int (*)(int, int), int, int>()); | ||
static_assert(check_equivalence_relation_subsumes_relation<int (*)(int, double), int, double>()); | ||
static_assert(check_equivalence_relation_subsumes_relation<R, S1, S1>()); | ||
static_assert(check_equivalence_relation_subsumes_relation<R, S1, S2>()); | ||
|
||
// clang-format off | ||
template<class F, class T, class U> | ||
requires cuda::std::relation<F, T, U> && true | ||
constexpr bool check_relation_subsumes_equivalence_relation() { | ||
return true; | ||
} | ||
|
||
template<class F, class T, class U> | ||
requires cuda::std::equivalence_relation<F, T, U> | ||
constexpr bool check_relation_subsumes_equivalence_relation() { | ||
return false; | ||
} | ||
// clang-format on | ||
|
||
static_assert(check_relation_subsumes_equivalence_relation<int (*)(int, int), int, int>()); | ||
static_assert(check_relation_subsumes_equivalence_relation<int (*)(int, double), int, double>()); | ||
static_assert(check_relation_subsumes_equivalence_relation<R, S1, S1>()); | ||
static_assert(check_relation_subsumes_equivalence_relation<R, S1, S2>()); | ||
|
||
// clang-format off | ||
template<class F, class T, class U> | ||
requires cuda::std::equivalence_relation<F, T, T> && cuda::std::equivalence_relation<F, U, U> | ||
constexpr bool check_equivalence_relation_subsumes_itself() { | ||
return false; | ||
} | ||
|
||
template<class F, class T, class U> | ||
requires cuda::std::equivalence_relation<F, T, U> | ||
constexpr bool check_equivalence_relation_subsumes_itself() { | ||
return true; | ||
} | ||
// clang-format on | ||
|
||
static_assert( | ||
check_equivalence_relation_subsumes_itself<int (*)(int, int), int, int>()); | ||
static_assert(check_equivalence_relation_subsumes_itself<R, S1, S1>()); |
Oops, something went wrong.