This article demonstrates a technique to simulate Python-style keyword arguments in C++ by using structs with designated initializers, improving code readability without macros or template magic.
# Faking keyword arguments to functions in C++
Source: [https://nibblestew.blogspot.com/2026/06/faking-keyword-arguments-to-functions.html](https://nibblestew.blogspot.com/2026/06/faking-keyword-arguments-to-functions.html)
One of the many nice language features in Python are keyword arguments\. They make some types of APIs concise and readable\. Like so:
[](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipxolHgFLDFeecuGLIStC9PHsYEy2ORmWmYmGLW3OAR562zUbR5Yl3RtBcdwHDCrPB7gUBBQUzVR-GrRJr4ZTzbGiLoRXUzYKa_KIzL0qnCsY9_DZOTvlW92oJKv0P6RWx4gl1vkUzGtBOX_JYK2-L3SyXoBrDwypMLjG24g8N8rtQQngNvcLiPdoJ_Bs/s1454/python_kwargs.png)
Unfortunately C does not have keyword arguments and, by extension, neither does C\+\+\. Adding them as a language feature would take 15\-20 years of effort, most of which would consist of trying to convince people via email that such a feature is important and should be added\.
There have been attempts to implement this via macros and template magic \([link](https://www.boost.org/doc/libs/latest/libs/parameter/doc/html/index.html)\), but they have not seen widespread usage probably because they are using macros and template magic\. However it turns out that with modern language features you can fake keyword arguments fairly convincingly\. Like so:
[](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT2a2DpfVw3HgiPZ5YMC3ppEOpBRy7At4tsGbRVGgP89w-fwV0VojJzk2rSzMWtu2vLkU_YJjVPW3qcLI86pVcOuizA-HFiNocqnMI9p75JkX4_yfRYjyUThm8nsnmpkD5rnsani1R8Z5BoSsd8POUVAfHGMBlSpAo9unaAGHHW5kt1e_g5CUQbH6K21E/s910/cpp_kwargs.png)
Theadd\_argumentmethod takes a single argument which is a struct\. The extra curly braces inside the parentheses boil down to "whatever the underlying argument is, construct it in place with these parameters"\. The dotted names are designated initializers, so those fields get the specified value whereas other fields get their default values\.
And there you go, keyword arguments in C\+\+\. You just have to squint a bit and pretend not to see the extra curly braces\.
Explores when C++ compilers can devirtualize virtual function calls, covering cases like known dynamic types and final keyword, with comparisons across GCC, Clang, MSVC, and ICC.
C++26 introduces two new function wrappers: std::copyable_function, which provides a copyable, const-correct alternative to std::function, and std::function_ref, a non-owning callable reference with reference semantics.
A humorous educational article covering C programming fundamentals such as forward declarations, operator precedence, unconditional jumps, and basic arithmetic with intentionally silly code examples.
The article discusses the pros and cons of using C-style void* pointers versus uint8_t* and std::span for passing memory blobs in C++, arguing for the simplicity and readability of void*.