boostorg / system

Boost.org system module
http://boost.org/libs/system
36 stars 85 forks source link

n-ary transform function #121

Open grisumbras opened 5 months ago

grisumbras commented 5 months ago

The way I see it, it should be something like system::invoke that invokes a callable with N (0+) arguments of which some can be results. In addition, for convenience it should invoke the callable similar to what std::invoke does.

Example

Foo
Processor::compose_abc(A const&, B const&, C const&);

system::result<Foo>
read_config(Processor& p, Config const& config)
{
    auto a = maybe_get_a(config);
    auto b = maybe_get_b(config);
    auto c = maybe_get_c(config);
    return system::invoke(&Processor::compose_abc, p, a, b, c);
}

One interesting question is whether result<void> arguments should be allowed. The semantics would be to ignore them when invoking the callable, but that would complicate implementation.

pdimov commented 5 months ago

I assume the error types would need to match?

grisumbras commented 5 months ago

Yes, definitely.

pdimov commented 3 months ago

https://godbolt.org/z/qencc7cnz

grisumbras commented 3 months ago

Looks pretty good. It doesn't do the invoke thing that allows using pointers to members. Is that planned?

Also, I requested nullary function support, but now I don't remember what for.

pdimov commented 3 months ago

Member function support is something I need to add to the "monadic" operators as well. I'll figure something out.