From 2cae20651a4b6c12cb305ae4eaf048d640715058 Mon Sep 17 00:00:00 2001 From: Aleksey Loginov Date: Thu, 19 Sep 2024 23:08:32 +0300 Subject: [PATCH 1/3] improve static_asserts --- src/rpp/rpp/observables/observable.hpp | 3 ++- src/rpp/rpp/operators/finally.hpp | 2 +- src/rpp/rpp/operators/fwd.hpp | 8 ++------ src/rpp/rpp/operators/group_by.hpp | 4 ++-- src/rpp/rpp/operators/map.hpp | 2 +- src/rpp/rpp/utils/constraints.hpp | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/rpp/rpp/observables/observable.hpp b/src/rpp/rpp/observables/observable.hpp index a0a0daea7..75d67bed6 100644 --- a/src/rpp/rpp/observables/observable.hpp +++ b/src/rpp/rpp/observables/observable.hpp @@ -339,7 +339,8 @@ namespace rpp if constexpr (requires { typename std::decay_t::template operator_traits; }) { using result_type = typename std::decay_t::template operator_traits::result_type; - return observable, Strategy>>{std::forward(op), std::move(m_strategy)}; + if constexpr (requires { typename std::decay_t::template operator_traits::result_type; }) // narrow compilataion error a bit + return observable, Strategy>>{std::forward(op), std::move(m_strategy)}; } else { diff --git a/src/rpp/rpp/operators/finally.hpp b/src/rpp/rpp/operators/finally.hpp index 88102784a..42c4c424b 100644 --- a/src/rpp/rpp/operators/finally.hpp +++ b/src/rpp/rpp/operators/finally.hpp @@ -53,7 +53,7 @@ namespace rpp::operators * @ingroup utility_operators * @see https://reactivex.io/documentation/operators/do.html */ - template LastFn> + template auto finally(LastFn&& last_fn) { return details::finally_t>{std::forward(last_fn)}; diff --git a/src/rpp/rpp/operators/fwd.hpp b/src/rpp/rpp/operators/fwd.hpp index 131f04036..fe6ea6af5 100644 --- a/src/rpp/rpp/operators/fwd.hpp +++ b/src/rpp/rpp/operators/fwd.hpp @@ -53,7 +53,7 @@ namespace rpp::operators requires (!utils::is_not_template_callable || std::same_as>) auto filter(Fn&& predicate); - template LastFn> + template auto finally(LastFn&& lastFn); template @@ -79,12 +79,8 @@ namespace rpp::operators template typename Subject = rpp::subjects::publish_subject> auto multicast(); - template - requires (!utils::is_not_template_callable || rpp::constraint::observable>) - auto flat_map(Fn&& callable); - template - requires constraint::observables_of_same_type, std::decay_t...> + requires (constraint::observables_of_same_type, std::decay_t...>) auto merge_with(TObservable&& observable, TObservables&&... observables); auto merge(); diff --git a/src/rpp/rpp/operators/group_by.hpp b/src/rpp/rpp/operators/group_by.hpp index 4e1d8d1fc..5aa4e0210 100644 --- a/src/rpp/rpp/operators/group_by.hpp +++ b/src/rpp/rpp/operators/group_by.hpp @@ -166,8 +166,8 @@ namespace rpp::operators::details template struct operator_traits { - static_assert(std::invocable, "KeySelector is not invocacble with T"); - static_assert(std::invocable, "ValueSelector is not invocable with T"); + static_assert(!std::same_as>, "KeySelector is not invocacble with T"); + static_assert(!std::same_as>, "ValueSelector is not invocable with T"); static_assert(std::strict_weak_order, rpp::utils::decayed_invoke_result_t>, "KeyComparator is not invocable with result of KeySelector"); using result_type = grouped_observable, rpp::utils::decayed_invoke_result_t, group_by_observable_strategy>>; diff --git a/src/rpp/rpp/operators/map.hpp b/src/rpp/rpp/operators/map.hpp index 74e3fad4d..43ec6d0d1 100644 --- a/src/rpp/rpp/operators/map.hpp +++ b/src/rpp/rpp/operators/map.hpp @@ -50,7 +50,7 @@ namespace rpp::operators::details template struct operator_traits { - static_assert(std::invocable, "Fn is not invocable with T"); + static_assert(!std::same_as>, "Fn is not invocable with T"); using result_type = std::invoke_result_t; diff --git a/src/rpp/rpp/utils/constraints.hpp b/src/rpp/rpp/utils/constraints.hpp index 87e9d5792..8a47e751a 100644 --- a/src/rpp/rpp/utils/constraints.hpp +++ b/src/rpp/rpp/utils/constraints.hpp @@ -31,7 +31,7 @@ namespace rpp::constraint concept variadic_decayed_same_as = sizeof...(Types) == 1 && (decayed_same_as && ...); template - concept static_pointer_convertible_to = requires { static_cast(std::declval()); }; + concept static_pointer_convertible_to = requires(T* ptr) { static_cast(ptr); }; template concept iterable = requires(R& rng) { From c2785b19df1c1d2adcb32f61e4376bddd1068a0f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:08:53 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/rpp/rpp/observables/observable.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpp/rpp/observables/observable.hpp b/src/rpp/rpp/observables/observable.hpp index 75d67bed6..19bc89521 100644 --- a/src/rpp/rpp/observables/observable.hpp +++ b/src/rpp/rpp/observables/observable.hpp @@ -339,7 +339,7 @@ namespace rpp if constexpr (requires { typename std::decay_t::template operator_traits; }) { using result_type = typename std::decay_t::template operator_traits::result_type; - if constexpr (requires { typename std::decay_t::template operator_traits::result_type; }) // narrow compilataion error a bit + if constexpr (requires { typename std::decay_t::template operator_traits::result_type; }) // narrow compilataion error a bit return observable, Strategy>>{std::forward(op), std::move(m_strategy)}; } else From d0d978ecbb5cae970153e751869d9c77b87040dc Mon Sep 17 00:00:00 2001 From: Aleksey Loginov Date: Thu, 19 Sep 2024 23:20:25 +0300 Subject: [PATCH 3/3] fix --- src/rpp/rpp/operators/fwd.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpp/rpp/operators/fwd.hpp b/src/rpp/rpp/operators/fwd.hpp index fe6ea6af5..5f3b591f6 100644 --- a/src/rpp/rpp/operators/fwd.hpp +++ b/src/rpp/rpp/operators/fwd.hpp @@ -80,7 +80,7 @@ namespace rpp::operators auto multicast(); template - requires (constraint::observables_of_same_type, std::decay_t...>) + requires constraint::observables_of_same_type, std::decay_t...> auto merge_with(TObservable&& observable, TObservables&&... observables); auto merge();