fn::discard
Fri Apr 18 2025

Defined in#include <fn/discard.hpp>

Discard the value explicitly.
This is useful when only side-effects are desired and the final value is not needed.
Use through the fn::discard nielbloid.

Call signatures

fn::discard_t
::
operator()
()
Unconditionally discards the value.

Return value

void

Examples

struct Error final {
  std::string what;
};

...

fn::optional<int> op{42};

op | fn::inspect([](int v) noexcept { REQUIRE(v == 42); })
1
| fn::discard();
1Observe for side-effects only
42 is observed by inspect and the value is discarded by discard (no warning for discarded result of inspect).