Skip to content

Automatically unpack tuples in map/filter etc #225

@tcbrindle

Description

@tcbrindle

Today's Advent of Code was a reminder that even with flux::unpack, working with sequences which yield tuples can be really ugly:

screenshot

To avoid this, we could automatically unpack tuples in sequence adaptors where possible, allowing users to write something like

auto seq = flux::zip(get_vector(), get_string())
                  .map([](int i, char c) { ... });

that is, without needing to wrap the lambda in flux::unpack.

I think the best way to do this is to add our own flux::invoke(f, args...) which:

  • First tries std::invoke(f, args...)
  • If that fails, and if the args... pack has exactly one element, tries again with std::invoke(unpack(f), args...)

We'd also need corresponding versions of invoke_result_t and the invocable concept.

If we make this change, it would also be worth looking at the codegen of e.g cartesian_product_map and zip_map vs cartesian_product.map and zip.map to see whether it's worth keeping the former around.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions