Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/stdx/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ constexpr auto derived_from =
template <typename T, typename U>
constexpr auto same_as = std::is_same_v<T, U> and std::is_same_v<U, T>;

template <typename T, typename... Us>
constexpr auto same_any = (... or same_as<T, Us>);

template <typename T, typename... Us>
constexpr auto same_none = not same_any<T, Us...>;

template <typename T, typename U>
constexpr auto same_as_unqualified =
is_same_unqualified_v<T, U> and is_same_unqualified_v<U, T>;
Expand Down Expand Up @@ -130,6 +136,12 @@ concept derived_from =
template <typename T, typename U>
concept same_as = std::is_same_v<T, U> and std::is_same_v<U, T>;

template <typename T, typename... Us>
constexpr auto same_any = (... or same_as<T, Us>);

template <typename T, typename... Us>
constexpr auto same_none = not same_any<T, Us...>;

template <typename T, typename U>
concept same_as_unqualified =
is_same_unqualified_v<T, U> and is_same_unqualified_v<U, T>;
Expand Down Expand Up @@ -222,6 +234,11 @@ concept same_as_unqualified =
template <typename T>
concept structural = is_structural_v<T>;

template <typename T, typename... Us>
constexpr auto same_any = (... or same_as<T, Us>);

template <typename T, typename... Us>
constexpr auto same_none = not same_any<T, Us...>;
} // namespace v1
} // namespace stdx

Expand Down
10 changes: 10 additions & 0 deletions test/concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ TEST_CASE("same_as", "[concepts]") {
static_assert(not stdx::same_as<float, int>);
}

TEST_CASE("same_any", "[concepts]") {
static_assert(stdx::same_any<int, float, bool, int>);
static_assert(not stdx::same_any<float, char, bool, int>);
}

TEST_CASE("same_none", "[concepts]") {
static_assert(stdx::same_none<int, float, bool, char>);
static_assert(not stdx::same_none<float, bool, char, float>);
}

TEST_CASE("same_as_unqualified", "[concepts]") {
static_assert(stdx::same_as_unqualified<int, int>);
static_assert(not stdx::same_as_unqualified<int, void>);
Expand Down