From b4e0dafc090c01cfef6115e921517f90bd1c7f0e Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Wed, 23 Oct 2024 16:21:55 +0200 Subject: [PATCH 1/2] Refactor drop_value to directly use operator() for partially applied use --- .../include/pika/execution/algorithms/drop_value.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp b/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp index 4c94e73cf..43a0e2776 100644 --- a/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp +++ b/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp @@ -138,10 +138,7 @@ namespace pika::execution::experimental { return drop_value_detail::drop_value_sender{PIKA_FORWARD(Sender, sender)}; } - // TODO: Use static operator() here, will go to customization afterwards anyway. - friend constexpr PIKA_FORCEINLINE auto tag_fallback_invoke(drop_value_t) - { - return detail::partial_algorithm{}; - } + using pika::functional::detail::tag_fallback::operator(); + auto operator()() const { return detail::partial_algorithm{}; } } drop_value{}; } // namespace pika::execution::experimental From 0248507ef16e49474801127ca8c40fa06bad51fa Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Wed, 23 Oct 2024 17:05:23 +0200 Subject: [PATCH 2/2] Add documentation for drop_value sender adaptor --- docs/api.rst | 6 ++++ examples/documentation/CMakeLists.txt | 4 +-- .../drop_value_documentation.cpp | 36 +++++++++++++++++++ .../pika/execution/algorithms/drop_value.hpp | 12 +++++-- 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 examples/documentation/drop_value_documentation.cpp diff --git a/docs/api.rst b/docs/api.rst index d746c054f..c14a27680 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -75,6 +75,12 @@ The ``pika/init.hpp`` header provides functionality to manage the pika runtime. The ``pika/execution.hpp`` header provides functionality related to ``std::execution``. +.. doxygenvariable:: pika::execution::experimental::drop_value + +.. literalinclude:: ../examples/documentation/drop_value_documentation.cpp + :language: c++ + :start-at: #include + .. doxygenvariable:: pika::execution::experimental::split_tuple .. literalinclude:: ../examples/documentation/split_tuple_documentation.cpp diff --git a/examples/documentation/CMakeLists.txt b/examples/documentation/CMakeLists.txt index 78d198aa0..932652c35 100644 --- a/examples/documentation/CMakeLists.txt +++ b/examples/documentation/CMakeLists.txt @@ -4,8 +4,8 @@ # Distributed under the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -set(example_programs hello_world_documentation init_hpp_documentation split_tuple_documentation - when_all_vector_documentation +set(example_programs drop_value_documentation hello_world_documentation init_hpp_documentation + split_tuple_documentation when_all_vector_documentation ) foreach(example_program ${example_programs}) diff --git a/examples/documentation/drop_value_documentation.cpp b/examples/documentation/drop_value_documentation.cpp new file mode 100644 index 000000000..d5dfa85df --- /dev/null +++ b/examples/documentation/drop_value_documentation.cpp @@ -0,0 +1,36 @@ +// Copyright (c) 2024 ETH Zurich +// +// SPDX-License-Identifier: BSL-1.0 +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +#include + +#include +#include + +struct custom_type +{ +}; + +int main(int argc, char* argv[]) +{ + namespace ex = pika::execution::experimental; + namespace tt = pika::this_thread::experimental; + + pika::start(argc, argv); + ex::thread_pool_scheduler sched{}; + + auto s = ex::just(42, custom_type{}, std::tuple("hello")) | ex::drop_value() | + // No matter what is sent to drop_value, it won't be sent from drop_value + ex::then([] { fmt::print("I got nothing...\n"); }); + tt::sync_wait(std::move(s)); + + pika::finalize(); + pika::stop(); + + return 0; +} diff --git a/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp b/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp index 43a0e2776..b293c097f 100644 --- a/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp +++ b/libs/pika/execution/include/pika/execution/algorithms/drop_value.hpp @@ -129,8 +129,7 @@ namespace pika::drop_value_detail { } // namespace pika::drop_value_detail namespace pika::execution::experimental { - inline constexpr struct drop_value_t final - : pika::functional::detail::tag_fallback + struct drop_value_t final : pika::functional::detail::tag_fallback { template )> friend constexpr PIKA_FORCEINLINE auto tag_fallback_invoke(drop_value_t, Sender&& sender) @@ -140,5 +139,12 @@ namespace pika::execution::experimental { using pika::functional::detail::tag_fallback::operator(); auto operator()() const { return detail::partial_algorithm{}; } - } drop_value{}; + }; + + /// \brief Ignores all values sent by the predecessor sender, sending none itself. + /// + /// Sender adaptor that takes any sender and returns a new sender that sends no values. + /// + /// Added in 0.6.0. + inline constexpr drop_value_t drop_value{}; } // namespace pika::execution::experimental