Skip to content

P3777 Named function parameters #47

@eisenwave

Description

@eisenwave

The idea is to have named parameters with similar syntax to designated initializers:

void f(int .x, int .y); // explicit opt-in

f(.y = 0, .x = 1);

The benefits of this are:

  • Less bug-prone uses of functions like std::lerp or std::memcpy, where arguments are easily confused.
  • In general, being able to pass more parameters without getting confused, and with expressing intent at the call site.
  • Avoiding magic numbers, like f(.flag = true), without needing additional variables.
  • Massively simplifying overload resolution. For example, std::ranges::all_of(.exec = /* ... */) would eliminate every algorithm that does not accept an execution policy from the overload set, which gives you better error messages and faster compilation.

Unfortunately, this proposal is quite large, and I don't know when I'll get around to dedicated time to it.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3777new-proposalIdea/discussion for possible new proposals

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions