Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for drop_value sender adaptor #1287

Merged
merged 2 commits into from
Oct 30, 2024
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
6 changes: 6 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
36 changes: 36 additions & 0 deletions examples/documentation/drop_value_documentation.cpp
Original file line number Diff line number Diff line change
@@ -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 <pika/execution.hpp>
#include <pika/init.hpp>

#include <fmt/printf.h>

#include <tuple>
#include <utility>

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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,22 @@ 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<drop_value_t>
struct drop_value_t final : pika::functional::detail::tag_fallback<drop_value_t>
{
template <typename Sender, PIKA_CONCEPT_REQUIRES_(is_sender_v<Sender>)>
friend constexpr PIKA_FORCEINLINE auto tag_fallback_invoke(drop_value_t, Sender&& sender)
{
return drop_value_detail::drop_value_sender<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<drop_value_t>{};
}
} drop_value{};
using pika::functional::detail::tag_fallback<drop_value_t>::operator();
auto operator()() const { return detail::partial_algorithm<drop_value_t>{}; }
};

/// \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
Loading