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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Fun

Fun

Photo of reflection

reflection

Photo of keyword arguments

keyword arguments

Related news:

News photo

Sony apparently hates fun, axes the Bloodborne demake with another copyright claim

News photo

Don't make fun of renowned author Dan Brown (2013)

News photo

Sniper Elite: Resistance - unambitious tech but well executed and lots of fun