Obscure C++ Features
madebyevan.com
madebyevan.com
I didn't know you could overload the comma operator that way. The comma operator was for use in C macros, for when multiple expressions were necessary. It should have been deprecated in C++.
The comma operator has different precedence inside and outside square brackets.
tab(1,2)
is a function call with two arguments. tab[1,2]
is an invocation of the comma operator. You can't overload "operator[]" with multiple arguments and simulate multidimensional arrays.You may not use it, but you can appreciate it's very useful if you want that fine grained control that you're using c++ for in the first place.
Most of the other examples are just pure weirdness that you should never use. The kind you find in online employment exams.
[1] http://scottmeyers.blogspot.com/2016/11/help-me-sort-out-mea...
Discussion on hackernews about that blog post by Scott Meyers: https://news.ycombinator.com/item?id=13014429
Overall I disagree with some of the commenters who take one look at {{}} and cue the syntax bashing. I've found that many of the new syntactic conveniences in the language have brought a net positive to expressiveness and elegance.
Furthermore, the first 'C++ feature' is not even a feature. It is merely the result of the preprocessor translating a[b] to *(a+b). C has it too.
It works though, "works" as in "it will compile".
It's considered bad practice, yep. I would absolutely reject any code review that abused the preprocessor like that.
The only legitimate way to use it I've seen is for "white box" testing... when you have a nontrivial amount of private helper code and you want to be able to test it. Then defining "private" to be "public" for only that test compilation cuts down on the amount of work needed with basically no risk.
That being said, I prefer refactoring out all that private data and code into utilities and such. There are other ways to get good encapsulation in C++, if that's the concern.
C++ standard defines the syntax of a postfix expression as this
postfix-expression:
primary-expression
postfix-expression[expression]
postfix-expression[braced-init-list]
[expression]primary-expression is not validMore readable as in "I want to read code fast"? No.
I much prefer C style languages over Pascal style languages.