Object key literals #4192
Replies: 5 comments 2 replies
-
I don't see the
|
Beta Was this translation helpful? Give feedback.
-
If you think it's too long then you could shorten the literal suffix to Not sure if I understand your question about the "= value". If you are wondering about implementation, it is a simple matter of creating a new literal suffix that returns a proxy object (say, of type |
Beta Was this translation helpful? Give feedback.
-
I think that it is mostly subjective which syntax is preferable; I wouldn't suggest that my preference be imposed by replacing the current syntax. It is just an additional option for those who prefer it. At the very top of the readme for this repo, it says the following:
And that is what the proposed syntax does -- it uses operators to make the syntax resemble Python a bit more closely. In Python it would essentially be this: j = {
"hello": 42,
"world": None
} or j = dict(
hello=42,
world=None
) In C++ we can't do the former, but we can do the latter. I think that the proposed syntax more closely resembles both of the Python ways than the current syntax with additional braces. But as I mentioned, I am not proposing to replace the existing syntax, it's just an alternative for those who consider it subjectively better. |
Beta Was this translation helpful? Give feedback.
-
For this case: json j = {
"hello"_key,
"world"_key,
}; We can make it give a clean compile error by having |
Beta Was this translation helpful? Give feedback.
-
Ok thx, will close then. |
Beta Was this translation helpful? Give feedback.
-
That would create an object with the given key/value pairs, which I think is nicer that the current syntax {{k,v},{k,v}}.
Should be simple to implement.
Beta Was this translation helpful? Give feedback.
All reactions