C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Extend monadic operations of std::expected and std::optional by allowing taking extra arguments

From: Vitaly Fanaskov <vt4a2h_at_[hidden]>
Date: Mon, 06 Jul 2026 16:53:20 +0000
Absolutely, we can use the existing abstraction. Although I'd be happier to use it like this:

const auto result = createComponent(ctx, path, metadata)
   .and_then(&Database::store, &db, std::placeholders::_1);

I.e. have a built-in "bind" in a sense. At the same time, it'd be nice to avoid any confusion, because we can bind a single argument only. The name "_1" can be problematic.


On Monday, July 6th, 2026 at 15:34, Bjorn Reese via Std-Proposals <std-proposals_at_[hidden]> wrote:

> On 7/5/26 23:45, Vitaly Fanaskov via Std-Proposals wrote:
>
> > This paper aims to extend monadic operations of std::expected and
> > std::optional by allowing taking extra arguments. These arguments will
> > be forwarded to the given function, passed after the first argument with
> > the contained value. When applicable, the position of the contained
> > value can be controlled using a placeholder mechanism.
>
> The new placeholder type is unnecessary as
>
> const auto result = createComponent(ctx, path, metaData)
> .and_then(&Database::store, db, std::placeholders::value);
>
> is essentially
>
> const auto result = createComponent(ctx, path, metadata)
> .and_then(std::bind(&Database::store, &db, std::placeholders::_1));
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2026-07-06 16:53:29