ReactivePlusPlus
ReactiveX implementation for C++20
Toggle main menu visibility
Loading...
Searching...
No Matches
constraints.hpp
1
// ReactivePlusPlus library
2
//
3
// Copyright Aleksey Loginov 2023 - present.
4
// Distributed under the Boost Software License, Version 1.0.
5
// (See accompanying file LICENSE_1_0.txt or copy at
6
// https://www.boost.org/LICENSE_1_0.txt)
7
//
8
// Project home: https://github.com/AlexInLog/ReactivePlusPlus
9
//
10
11
#pragma once
12
13
#include <concepts>
14
#include <iterator>
15
16
namespace
rpp::constraint
17
{
18
template
<
typename
T,
typename
Type>
19
concept
decayed_same_as
= std::same_as<std::decay_t<T>, std::decay_t<Type>>;
20
21
template
<
typename
T>
22
concept
decayed_type
= std::same_as<std::decay_t<T>, T>;
23
24
template
<
typename
T,
typename
... Types>
25
concept
any_of
= (std::same_as<T, Types> || ...);
26
27
template
<
typename
T,
typename
... Types>
28
concept
decayed_any_of
= (
decayed_same_as<T, Types>
|| ...);
29
30
template
<
typename
Type,
typename
... Types>
31
concept
variadic_decayed_same_as
=
sizeof
...(Types) == 1 && (
decayed_same_as<Type, Types>
&& ...);
32
33
template
<
typename
T,
typename
Target>
34
concept
static_pointer_convertible_to
=
requires
(T* ptr) {
static_cast<
Target*
>
(ptr); };
35
36
template
<
typename
R>
37
concept
iterable
=
requires
(R& rng) {
38
std::cbegin(rng);
39
std::cend(rng);
40
};
41
42
template
<
typename
T,
typename
... Args>
43
concept
is_constructible_from
=
requires
(Args... args) {
44
{
45
T{
static_cast<
Args&&
>
(args)...}
46
} -> std::same_as<T>;
47
};
48
49
template
<
typename
Ret,
typename
Fn,
typename
... Args>
50
concept
invocable_r_v
= std::invocable<Fn, Args...> && std::same_as<Ret, std::invoke_result_t<Fn, Args...>>;
51
52
template
<
typename
Fn,
typename
... Args>
53
concept
is_nothrow_invocable
= std::is_nothrow_invocable_v<Fn, Args...>;
54
55
template
<
typename
T>
56
concept
hashable
=
requires
(T a) {
57
{
58
std::hash<T>{}(a)
59
} -> std::convertible_to<std::size_t>;
60
};
61
}
// namespace rpp::constraint
rpp::constraint::any_of
Definition
constraints.hpp:25
rpp::constraint::decayed_any_of
Definition
constraints.hpp:28
rpp::constraint::decayed_same_as
Definition
constraints.hpp:19
rpp::constraint::decayed_type
Definition
constraints.hpp:22
rpp::constraint::hashable
Definition
constraints.hpp:56
rpp::constraint::invocable_r_v
Definition
constraints.hpp:50
rpp::constraint::is_constructible_from
Definition
constraints.hpp:43
rpp::constraint::is_nothrow_invocable
Definition
constraints.hpp:53
rpp::constraint::iterable
Definition
constraints.hpp:37
rpp::constraint::static_pointer_convertible_to
Definition
constraints.hpp:34
rpp::constraint::variadic_decayed_same_as
Definition
constraints.hpp:31
src
rpp
rpp
utils
constraints.hpp
Generated by
1.17.0