Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Implement concept emulation for C++14 / C++17
Browse files Browse the repository at this point in the history
This also ports all the standard concepts from libc++ preserving the new modular organization.
  • Loading branch information
miscco committed Sep 6, 2022
1 parent d4bd0f6 commit 535fe2e
Show file tree
Hide file tree
Showing 73 changed files with 12,479 additions and 1 deletion.
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; }
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>());
Loading

0 comments on commit 535fe2e

Please sign in to comment.