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
22 changes: 21 additions & 1 deletion src/rpp/rpp/observables/constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,33 @@
#pragma once

#include <rpp/observables/fwd.hpp>
#include <rpp/observables/type_traits.hpp>

#include <concepts>

namespace rpp::constraint
{
template<typename T> concept observable = std::derived_from<std::decay_t<T>, details::observable_tag>;
}

namespace rpp::utils
{
namespace details
{
template<rpp::constraint::observable T>
struct extract_observable_type
{
template<typename TT>
static TT deduce(const virtual_observable<TT>&);

using type = decltype(deduce(std::declval<std::decay_t<T>>()));
};
} // namespace details

template<rpp::constraint::observable T>
using extract_observable_type_t = typename details::extract_observable_type<T>::type;
} // namespace rpp::utils

namespace rpp::constraint
{
template<typename T, typename Type> concept observable_of_type = observable<T> && std::same_as<utils::extract_observable_type_t<T>, Type>;
} // namespace rpp::constraint
4 changes: 2 additions & 2 deletions src/rpp/rpp/observables/specific_observable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class specific_observable : public interface_observable<Type, specific_observabl
* \return subscription on this observable which can be used to unsubscribe
*/
template<constraint::observer_of_type<Type> TObserver>
composite_subscription subscribe(constraint::decayed_same_as<composite_subscription> auto&& sub, TObserver&& observer) const
composite_subscription subscribe(composite_subscription sub, TObserver&& observer) const
Comment thread
AlexInLog marked this conversation as resolved.
Comment thread
AlexInLog marked this conversation as resolved.
{
return subscribe_impl(specific_subscriber<Type, std::decay_t<TObserver>>{std::forward<decltype(sub)>(sub), std::forward<TObserver>(observer)});
return subscribe_impl(specific_subscriber<Type, std::decay_t<TObserver>>{std::move(sub), std::forward<TObserver>(observer)});
}

/**
Expand Down
27 changes: 0 additions & 27 deletions src/rpp/rpp/observables/type_traits.hpp

This file was deleted.

25 changes: 23 additions & 2 deletions src/rpp/rpp/observers/constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#pragma once

#include <rpp/observers/fwd.hpp>
#include <rpp/observers/type_traits.hpp>

#include <type_traits>

Expand All @@ -25,5 +24,27 @@ namespace rpp::constraint
template<typename T> concept observer = std::is_base_of_v<details::observer_tag, std::decay_t<T>> && !std::is_base_of_v<details::subscriber_tag, std::decay_t<T>>;

template<typename T> concept decayed_observer = observer<T> && decayed_type<T>;
template<typename T, typename Type> concept observer_of_type = observer<T> && std::is_same_v<utils::extract_observer_type_t<T>, Type>;
}

namespace rpp::utils
{
namespace details
{
template<rpp::constraint::observer T>
struct extract_observer_type
{
template<typename TT>
static TT deduce(const interface_observer<TT>&);

using type = decltype(deduce(std::declval<std::decay_t<T>>()));
};

} // namespace details
template<rpp::constraint::observer T>
using extract_observer_type_t = typename details::extract_observer_type<T>::type;
} // namespace rpp::utils

namespace rpp::constraint
{
template<typename T, typename Type> concept observer_of_type = observer<T> && std::same_as<utils::extract_observer_type_t<T>, Type>;
} // namespace rpp::constraint
1 change: 0 additions & 1 deletion src/rpp/rpp/observers/dynamic_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <rpp/observers/constraints.hpp> // wrapping constructor
#include <rpp/observers/interface_observer.hpp> // base class
#include <rpp/observers/specific_observer.hpp> // state
#include <rpp/observers/type_traits.hpp> // extract observer type
#include <rpp/utils/function_traits.hpp> // extract function args
#include <rpp/utils/functors.hpp> // default arguments

Expand Down
28 changes: 13 additions & 15 deletions src/rpp/rpp/observers/state_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,20 @@ template<constraint::decayed_type Type,
typename State,
std::invocable<Type, State> OnNext,
std::invocable<std::exception_ptr, State> OnError,
std::invocable<State> OnCompleted,
constraint::decayed_same_as<composite_subscription> Subscription = composite_subscription>
auto create_subscriber_with_state_impl(State&& state,
OnNext&& on_next,
OnError&& on_error,
OnCompleted&& on_completed,
Subscription&& sub = composite_subscription{})
std::invocable<State> OnCompleted>
auto create_subscriber_with_state_impl(State&& state,
OnNext&& on_next,
OnError&& on_error,
OnCompleted&& on_completed,
rpp::composite_subscription&& sub = composite_subscription{})
{
return specific_subscriber<Type, state_observer<Type,
std::decay_t<State>,
std::decay_t<OnNext>,
std::decay_t<OnError>,
std::decay_t<OnCompleted>>>
{
std::forward<Subscription>(sub),
std::move(sub),
std::forward<State>(state),
std::forward<OnNext>(on_next),
std::forward<OnError>(on_error),
Expand All @@ -118,21 +117,20 @@ auto create_subscriber_with_state(State&& state,
}

template<constraint::decayed_type Type,
constraint::decayed_same_as<composite_subscription> Subscription,
typename State,
std::invocable<Type, State> OnNext,
std::invocable<std::exception_ptr, State> OnError,
std::invocable<State> OnCompleted>
auto create_subscriber_with_state(Subscription&& sub,
State&& state,
OnNext&& on_next,
OnError&& on_error,
OnCompleted&& on_completed)
auto create_subscriber_with_state(rpp::composite_subscription sub,
State&& state,
OnNext&& on_next,
OnError&& on_error,
OnCompleted&& on_completed)
{
return create_subscriber_with_state_impl<Type>(std::forward<State>(state),
std::forward<OnNext>(on_next),
std::forward<OnError>(on_error),
std::forward<OnCompleted>(on_completed),
std::forward<Subscription>(sub));
std::move(sub));
}
} // namespace rpp::details
24 changes: 0 additions & 24 deletions src/rpp/rpp/observers/type_traits.hpp

This file was deleted.

7 changes: 3 additions & 4 deletions src/rpp/rpp/operators/details/combining_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
#include <rpp/subscriptions/composite_subscription.hpp>

#include <atomic>
#include <memory>

namespace rpp::details::combining
{
template<constraint::decayed_type Type>
auto create_proxy_subscriber(rpp::composite_subscription subscription,
constraint::subscriber auto&& subscriber,
const std::shared_ptr<std::atomic_size_t>& count_of_on_completed_required,
std::atomic_size_t& count_of_on_completed_required,
auto&& on_next,
auto&& on_error,
auto&& on_completed)
{
++(*count_of_on_completed_required);
++count_of_on_completed_required;

return create_subscriber_with_state<Type>(std::move(subscription),
std::forward<decltype(subscriber)>(subscriber),
Expand All @@ -36,7 +35,7 @@ auto create_proxy_subscriber(rpp::composite_subscription subscription,

template<constraint::decayed_type Type>
auto create_proxy_subscriber(constraint::subscriber auto&& subscriber,
const std::shared_ptr<std::atomic_size_t>& count_of_on_completed_required,
std::atomic_size_t& count_of_on_completed_required,
auto&& on_next,
auto&& on_error,
auto&& on_completed)
Expand Down
11 changes: 7 additions & 4 deletions src/rpp/rpp/operators/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ IMPLEMENTATION_FILE(filter_tag);
namespace rpp::details
{
template<constraint::decayed_type Type, std::predicate<const Type&> Predicate>
auto filter_impl(Predicate&& predicate)
struct filter_impl
{
return [predicate = std::forward<Predicate>(predicate)](auto&& value, const constraint::subscriber_of_type<Type> auto& subscriber)
[[no_unique_address]] Predicate predicate;

void operator()(auto&& value, const constraint::subscriber_of_type<Type> auto& subscriber) const
{
if (predicate(utils::as_const(value)))
subscriber.on_next(std::forward<decltype(value)>(value));
};
}
}
};

} // namespace rpp::details
6 changes: 3 additions & 3 deletions src/rpp/rpp/operators/fwd/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct filter_tag;
namespace rpp::details
{
template<constraint::decayed_type Type, std::predicate<const Type&> Predicate>
auto filter_impl(Predicate&& predicate);
struct filter_impl;

template<constraint::decayed_type Type, typename SpecificObservable>
struct member_overload<Type, SpecificObservable, filter_tag>
Expand All @@ -47,13 +47,13 @@ struct member_overload<Type, SpecificObservable, filter_tag>
template<std::predicate<const Type&> Predicate>
auto filter(Predicate&& predicate) const& requires is_header_included<filter_tag, Predicate>
{
return static_cast<const SpecificObservable*>(this)->template lift <Type>(filter_impl<Type>(std::forward<Predicate>(predicate)));
return static_cast<const SpecificObservable*>(this)->template lift <Type>(filter_impl<Type, std::decay_t<Predicate>>{std::forward<Predicate>(predicate)});
}

template<std::predicate<const Type&> Predicate>
auto filter(Predicate&& predicate) && requires is_header_included<filter_tag, Predicate>
{
return std::move(*static_cast<SpecificObservable*>(this)).template lift<Type>(filter_impl<Type>(std::forward<Predicate>(predicate)));
return std::move(*static_cast<SpecificObservable*>(this)).template lift<Type>(filter_impl<Type, std::decay_t<Predicate>>{std::forward<Predicate>(predicate)});
}
};
} // namespace rpp::details
6 changes: 3 additions & 3 deletions src/rpp/rpp/operators/fwd/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct map_tag;
namespace rpp::details
{
template<constraint::decayed_type Type, std::invocable<Type> Callable>
auto map_impl(Callable&& callable);
struct map_impl;

template<constraint::decayed_type Type, typename SpecificObservable>
struct member_overload<Type, SpecificObservable, map_tag>
Expand Down Expand Up @@ -50,13 +50,13 @@ struct member_overload<Type, SpecificObservable, map_tag>
template<std::invocable<Type> Callable>
auto map(Callable&& callable) const & requires is_header_included<map_tag, Callable>
{
return static_cast<const SpecificObservable*>(this)->template lift<std::invoke_result_t<Callable, Type>>(map_impl<Type>(std::forward<Callable>(callable)));
return static_cast<const SpecificObservable*>(this)->template lift<std::invoke_result_t<Callable, Type>>(map_impl<Type, std::decay_t<Callable>>{std::forward<Callable>(callable)});
}

template<std::invocable<Type> Callable>
auto map(Callable&& callable) && requires is_header_included<map_tag, Callable>
{
return std::move(*static_cast<SpecificObservable*>(this)).template lift<std::invoke_result_t<Callable, Type>>(map_impl<Type>(std::forward<Callable>(callable)));
return std::move(*static_cast<SpecificObservable*>(this)).template lift<std::invoke_result_t<Callable, Type>>(map_impl<Type, std::decay_t<Callable>>{std::forward<Callable>(callable)});
}
};
} // namespace rpp::details
15 changes: 7 additions & 8 deletions src/rpp/rpp/operators/fwd/merge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <rpp/observables/constraints.hpp>
#include <rpp/observables/details/member_overload.hpp>
#include <rpp/observables/type_traits.hpp>

namespace rpp::details
{
Expand All @@ -22,10 +21,10 @@ struct merge_tag;
namespace rpp::details
{
template<constraint::decayed_type Type>
auto merge_impl();
struct merge_impl;

template<constraint::decayed_type Type, constraint::observable_of_type<Type> ...TObservables>
auto merge_with_impl(TObservables&& ...observables) requires (sizeof...(TObservables) >= 1);
template<constraint::decayed_type Type, constraint::observable_of_type<Type> ... TObservables>
auto merge_with_impl(TObservables&&... observables);

template<constraint::decayed_type Type, typename SpecificObservable>
struct member_overload<Type, SpecificObservable, merge_tag>
Expand Down Expand Up @@ -57,13 +56,13 @@ struct member_overload<Type, SpecificObservable, merge_tag>
template<typename ...Args>
auto merge() const& requires (is_header_included<merge_tag, Args...> && rpp::constraint::observable<Type>)
{
return static_cast<const SpecificObservable*>(this)->template lift<utils::extract_observable_type_t<Type>>(merge_impl<Type>());
return static_cast<const SpecificObservable*>(this)->template lift<utils::extract_observable_type_t<Type>>(merge_impl<Type>{});
}

template<typename ...Args>
auto merge() && requires (is_header_included<merge_tag, Args...>&& rpp::constraint::observable<Type>)
{
return std::move(*static_cast<SpecificObservable*>(this)).template lift<utils::extract_observable_type_t<Type>>(merge_impl<Type>());
return std::move(*static_cast<SpecificObservable*>(this)).template lift<utils::extract_observable_type_t<Type>>(merge_impl<Type>{});
}

/**
Expand Down Expand Up @@ -91,13 +90,13 @@ struct member_overload<Type, SpecificObservable, merge_tag>
template<constraint::observable_of_type<Type> ...TObservables>
auto merge_with(TObservables&&... observables) const& requires (is_header_included<merge_tag, TObservables...>&& sizeof...(TObservables) >= 1)
{
return static_cast<const SpecificObservable*>(this)->op(merge_with_impl<Type>(std::forward<TObservables>(observables)...));
return merge_with_impl<Type>(static_cast<const SpecificObservable*>(this)->as_dynamic(), std::forward<TObservables>(observables).as_dynamic()...);
}

template<constraint::observable_of_type<Type> ...TObservables>
auto merge_with(TObservables&&... observables) && requires (is_header_included<merge_tag, TObservables...> && sizeof...(TObservables) >= 1)
{
return std::move(*static_cast<SpecificObservable*>(this)).op(merge_with_impl<Type>(std::forward<TObservables>(observables)...));
return merge_with_impl<Type>(std::move(*static_cast<SpecificObservable*>(this)).as_dynamic(), std::forward<TObservables>(observables).as_dynamic()...);
}
};
} // namespace rpp::details
6 changes: 3 additions & 3 deletions src/rpp/rpp/operators/fwd/observe_on.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct observe_on_tag;
namespace rpp::details
{
template<constraint::decayed_type Type, schedulers::constraint::scheduler TScheduler>
auto observe_on_impl(TScheduler&& scheduler);
struct observe_on_impl;

template<constraint::decayed_type Type, typename SpecificObservable>
struct member_overload<Type, SpecificObservable, observe_on_tag>
Expand All @@ -43,13 +43,13 @@ struct member_overload<Type, SpecificObservable, observe_on_tag>
template<schedulers::constraint::scheduler TScheduler>
auto observe_on(TScheduler&& scheduler) const& requires is_header_included<observe_on_tag, TScheduler>
{
return static_cast<const SpecificObservable*>(this)->template lift<Type>(observe_on_impl<Type>(std::forward<TScheduler>(scheduler)));
return static_cast<const SpecificObservable*>(this)->template lift<Type>(observe_on_impl<Type, std::decay_t<TScheduler>>{std::forward<TScheduler>(scheduler)});
}

template<schedulers::constraint::scheduler TScheduler>
auto observe_on(TScheduler&& scheduler) && requires is_header_included<observe_on_tag, TScheduler>
{
return std::move(*static_cast<SpecificObservable*>(this)).template lift<Type>(observe_on_impl<Type>(std::forward<TScheduler>(scheduler)));
return std::move(*static_cast<SpecificObservable*>(this)).template lift<Type>(observe_on_impl<Type, std::decay_t<TScheduler>>{std::forward<TScheduler>(scheduler)});
}
};
} // namespace rpp::details
Loading