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..a5d66553d 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()); + } } }