ReactivePlusPlus
ReactiveX implementation for C++20
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/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <concepts>
14#include <iterator>
15
16namespace 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>
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
Definition constraints.hpp:25
Definition constraints.hpp:28
Definition constraints.hpp:19
Definition constraints.hpp:22
Definition constraints.hpp:56
Definition constraints.hpp:50
Definition constraints.hpp:43
Definition constraints.hpp:53
Definition constraints.hpp:37
Definition constraints.hpp:31