Get the latest tech news
Fun with C++26 reflection: Keyword Arguments
In this blog post, we’ll explore implementing order-independent keyword arguments for C++ through use of C++26’s proposed reflection features. I stumbled upon this technique while experimenting with reflection a few days ago and thought it might be worthwhile to share, as it nicely showcases just how powerful the proposed reflection features are.
While we might not be able to provide the desired syntax foo(3, x=5) directly, reflection allows us to inject new class types with named non-static data members. Lambda capture lists can be highly complex, but the vast majority of “odd” ones aren’t really meaningful in the context of named arguments. However, since we do not actually need to understand the expressions, it’s sufficient to ensure we do not prematurely stop on a, inside unbalanced curly braces, parentheses or square brackets when skipping forward to the next capture.
Or read this on Hacker News