C++ Weekly - Ep 229 - C++20: Why Deprecate The Comma Operator?

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

Рекомендации по теме
Комментарии
Автор

Given that I have never (in 35 years of C programming) used the comma operator in an index expression, I am ok with this

homomorphic
Автор

"this can be used to abuse... things. "
Here we go agaaain...

nexovec
Автор

Jason, I love your videos, but this video has a misleading title - it is only about deprecating comma operator inside the context of [], not in general. It's far too useful to deprecate it fully.

themeeman
Автор

Or they could have simply added the ':' operator, to get return std::vector<int>{1, 2, 3, 4}[0:2].
This could lead to cool features like steps (from:step:till) or until (:until).

akj
Автор

If that also means that a good linear algebra library would come to the standard I would welcome this.

gast
Автор

This seem counter to the typical "don't change the language when you can do it in the standard library" approach that most other new features take. You can easily implement multidimensional arrays without multiple pointer indirections by overloading [] and returning intermediate types.

peterfordham
Автор

This use of a comma operator is pretty different than being deprecated in general.

zvxcvxcz
Автор

This is why you're worth your weight in m.2 drives... you always notice things I, and many others did not notice.

vertigo
Автор

We have multi-dimensional arrays in C++. They just don't look like BASIC.

cflcookti
Автор

To be clear; the comma operator is not completely deprecated or at least according to the compiler, since it produces: "comma expression in array subscript".

So return log(), data[3]; would still be valid.

I think the comma operator is quite powerful, but I have used it only a handful of times over the last decades. And always in the conditions of if's and while's. Mainly for some quick debugging. I wonder how other people have used it and how often?

oisnowy
Автор

Always wondered why none of the libraries had implemented [x, y] for indexing. Now I know

ajinkyakamat
Автор

Given that I used the coma operator to do Expression Templates I am not in favor of removing all uses of the coma operator.
But yeah, it's a weird operator.

garyp.
Автор

It's deprecated? Ok… But it has exactly the behaviour I'd expect from it. 
Not because it's obvious, but because I have a C-Dev background, and I've seen nearly every operator being abused in a way or an other. 
In fact, I'd argue that the shift operator being used in streams is, indeed practical, but an, in my opinion, example of "abusive behaviour".

It's clever abuse, but still… In fact it feels like the comma operator or the plus operator would make more sense.
But, as I usually say, hindsight is 19/20.

LemonChieff
Автор

I didnt even know we had this operator! More than 4 years learning the language and there is still something to surprise a man

Raspredval
Автор

This is a very odd deprecation. For instance, I feel [2, 3] syntax is much weirder and less natural than the good old [2][3].

VioletGiraffe
Автор

If anything, the comma operator has been *underutilized*.

GregoryTheGrster
Автор

i thought that c++ couldn't surprise me anymore and then i found this video

ryusaki
Автор

wow, this is from vanilla C. I remember now.

bocckoka
Автор

Didn't this change to be requiring a parenthesis around it? Its interesting to see an operator case being deprecated for future removal (obviously for good reason, and I doubt, or really hope, nobody has ever done something that would make this a breaking change) but its not like the functionality is dying, (as deprecation implies, also its not the comma operator, its the comma operator directly as an indexer expression) the syntax is more being redefined. (I don't recall any any operators getting this before in C++, but I'm also not old enough to recall C++98)

Spartan
Автор

Why not overload the function call operator for multidimensional arrays? This is what I do in my constexpr linear algebra library.

keris