Fun with C++26 reflection: Keyword Arguments
1–10 of 147 posts
Re: Fun with C++26 reflection: Keyword Arguments
#2 FooArgs fooArgs;
fooArgs.y = 4;
foo(fooArgs); // Didn't set .x so it has default value
Three lines instead of one seems like a lot of overhead, but in practice you would only bother for a function that takes loads of arguments so the extra overhead is really much smaller.----
Smaller points:
Are the fields in FooArgs really initialised if they're not explicitly set? I can believe they are, after all it's brace initialisation. But IMHO that code isn't super obvious. I'd be more comfortable if they had default member initialisers, i.e., "int x = 0; int y = 0;" in FooArgs. In my version above, you really do need these (unless you remember to brace initialise).
It took me a while to see why they bothered to have a string template parameter for TypedArg in the first usage. It prevents mixing up two arguments: if TypedArg didn't have that, then you could call foo(y=3, x=2) and it would compile but have the effect that the parameter x would be 3 and y would be 2.
Re: Fun with C++26 reflection: Keyword Arguments
#3Re: Fun with C++26 reflection: Keyword Arguments
#4Re: Fun with C++26 reflection: Keyword Arguments
#5Can you imagine an engineer that is adamant on using his mystifying bespoke tool instead of just using a ruler. "But what if I have to measure it in the 4th dimension!?".
I was expecting something simple but good Lord, its kwargs. Not some magical asynchronous runtime.
inb4 there are still corner cases so you can't just say "users don't have to know the implementation details so only one person has to suffer". I bet money this abstraction is leaky.
Why can't you just do this at the language level like any sane person?
Re: Fun with C++26 reflection: Keyword Arguments
#6I just don't understand why some people are so fascinated by this. Can you all admit that this is not at all practical? I swear C++ folks like it for the sake of it. No other engineer do this. Only antiques people or whatever. Can you imagine an engineer that is adamant on using his mystifying bespoke tool instead of just using a ruler. "But what if I have to measure it in the 4th dimension!?". I was expecting someth…
But because this is C++ the committee designs the most insane and terrible version of reflection possible
Re: Fun with C++26 reflection: Keyword Arguments
#7I just don't understand why some people are so fascinated by this. Can you all admit that this is not at all practical? I swear C++ folks like it for the sake of it. No other engineer do this. Only antiques people or whatever. Can you imagine an engineer that is adamant on using his mystifying bespoke tool instead of just using a ruler. "But what if I have to measure it in the 4th dimension!?". I was expecting someth…
Reflection is spectacularly useful and sorely missed in C++ But because this is C++ the committee designs the most insane and terrible version of reflection possible
Re: Fun with C++26 reflection: Keyword Arguments
#8I just don't understand why some people are so fascinated by this. Can you all admit that this is not at all practical? I swear C++ folks like it for the sake of it. No other engineer do this. Only antiques people or whatever. Can you imagine an engineer that is adamant on using his mystifying bespoke tool instead of just using a ruler. "But what if I have to measure it in the 4th dimension!?". I was expecting someth…
But it is tremendously useful.
https://en.wikipedia.org/wiki/List_of_reflective_programming...
Re: Fun with C++26 reflection: Keyword Arguments
#9Poor, poor C++... cries in C
my_func(/*arg1=*/val1,/*arg2=*/val2)
And I suppose you could write a validator to make sure that this worked. Or using an anonymous structure in C99, or a named structure in C89. And of course a pointer if you care about register/stack usage etc.I'm not sure what the other options are.
Re: Fun with C++26 reflection: Keyword Arguments
#10Poor, poor C++... cries in C
I've seen cases where people do things like my_func(/*arg1=*/val1,/*arg2=*/val2) And I suppose you could write a validator to make sure that this worked. Or using an anonymous structure in C99, or a named structure in C89. And of course a pointer if you care about register/stack usage etc. I'm not sure what the other options are.