From f53bd4e18f10b7f907849441ad583f12e0ac7529 Mon Sep 17 00:00:00 2001 From: CorentinBT Date: Wed, 28 Aug 2024 21:52:19 +0200 Subject: [PATCH 1/2] Disambiguate tap operator --- src/rpp/rpp/operators/fwd.hpp | 2 ++ src/rpp/rpp/operators/tap.hpp | 2 ++ src/tests/rpp/test_tap.cpp | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/rpp/rpp/operators/fwd.hpp b/src/rpp/rpp/operators/fwd.hpp index 24d8ffce8..131f04036 100644 --- a/src/rpp/rpp/operators/fwd.hpp +++ b/src/rpp/rpp/operators/fwd.hpp @@ -156,6 +156,7 @@ namespace rpp::operators auto take_until(TObservable&& until_observable); template OnError = rpp::utils::empty_function_t> + requires utils::is_not_template_callable auto tap(OnError&& on_error); template OnCompleted = rpp::utils::empty_function_t<>> @@ -169,6 +170,7 @@ namespace rpp::operators template OnError = rpp::utils::empty_function_t, std::invocable<> OnCompleted = rpp::utils::empty_function_t<>> + requires utils::is_not_template_callable auto tap(OnNext&& on_next = {}, OnError&& on_error = {}, OnCompleted&& on_completed = {}); diff --git a/src/rpp/rpp/operators/tap.hpp b/src/rpp/rpp/operators/tap.hpp index c23af676d..be29f9117 100644 --- a/src/rpp/rpp/operators/tap.hpp +++ b/src/rpp/rpp/operators/tap.hpp @@ -90,6 +90,7 @@ namespace rpp::operators * @see https://reactivex.io/documentation/operators/do.html */ template OnError /* = rpp::utils::empty_function_t */> + requires utils::is_not_template_callable auto tap(OnError&& on_error) { using OnNext = rpp::utils::empty_function_any_t; @@ -156,6 +157,7 @@ namespace rpp::operators template OnError /* = rpp::utils::empty_function_t */, std::invocable<> OnCompleted /* = rpp::utils::empty_function_t<> */> + requires utils::is_not_template_callable auto tap(OnNext&& on_next /* = {} */, OnError&& on_error /* = {} */, OnCompleted&& on_completed /* = {} */) diff --git a/src/tests/rpp/test_tap.cpp b/src/tests/rpp/test_tap.cpp index e1b4de6f9..cda2243da 100644 --- a/src/tests/rpp/test_tap.cpp +++ b/src/tests/rpp/test_tap.cpp @@ -74,6 +74,20 @@ TEMPLATE_TEST_CASE("tap observes emissions and doesn't modify them", "", rpp::me CHECK(on_next_invoked == mock.get_total_on_next_count()); CHECK(on_completed_invoked == mock.get_on_completed_count()); } + + SECTION("pass on_next callback with auto argument") + { + size_t on_next_invoked = 0; + + obs | rpp::ops::tap([&](const auto&) { ++on_next_invoked; }) + | rpp::ops::subscribe(mock); + + CHECK(mock.get_received_values() == std::vector{1, 2, 3}); + CHECK(mock.get_on_error_count() == 0); + CHECK(mock.get_on_completed_count() == 1); + + CHECK(on_next_invoked == mock.get_total_on_next_count()); + } } } From 307ea9933b0862b2070403c69d66cbec36a13263 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 19:53:02 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/tests/rpp/test_tap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/rpp/test_tap.cpp b/src/tests/rpp/test_tap.cpp index cda2243da..a5d66553d 100644 --- a/src/tests/rpp/test_tap.cpp +++ b/src/tests/rpp/test_tap.cpp @@ -77,7 +77,7 @@ TEMPLATE_TEST_CASE("tap observes emissions and doesn't modify them", "", rpp::me SECTION("pass on_next callback with auto argument") { - size_t on_next_invoked = 0; + size_t on_next_invoked = 0; obs | rpp::ops::tap([&](const auto&) { ++on_next_invoked; }) | rpp::ops::subscribe(mock);