ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
constraints.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2022 - 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 <rpp/observers/fwd.hpp>
14
15#include <type_traits>
16
17namespace rpp::constraint
18{
19template<typename T> concept observer_callbacks_exists = requires(const T t)
20{
21 // t.on_next(...);
22 t.on_error(std::declval<std::exception_ptr>());
23 t.on_completed();
24};
25
26template<typename T> concept observer = std::is_base_of_v<details::observer_tag, std::decay_t<T>> && observer_callbacks_exists<T>;
27template<typename T> concept decayed_observer = observer<T> && decayed_type<T>;
28}
29
30namespace rpp::utils
31{
32namespace details
33{
34 template<rpp::constraint::observer T>
36 {
37 template<typename TT>
38 static TT deduce(const rpp::details::typed_observer_tag<TT>&);
39
40 using type = decltype(deduce(std::declval<std::decay_t<T>>()));
41 };
42
43} // namespace details
44template<rpp::constraint::observer T>
45using extract_observer_type_t = typename details::extract_observer_type<T>::type;
46} // namespace rpp::utils
47
48namespace rpp::constraint
49{
50template<typename T, typename Type> concept observer_on_next_exists = requires(const T t)
51{
52 t.on_next(std::declval<Type>());
53};
54
55template<typename T, typename Type> concept observer_of_type = observer<T> && std::same_as<utils::extract_observer_type_t<T>, Type> && observer_on_next_exists<T, Type>;
56} // namespace rpp::constraint
Definition: constraints.hpp:27
Definition: constraints.hpp:19
Definition: constraints.hpp:55
Definition: constraints.hpp:50
Definition: constraints.hpp:26
Definition: fwd.hpp:20
Definition: constraints.hpp:36