Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does (expr1, expr2) do on the right side of an assignment?

Tags:

c++

dictionary

I recently looked at my old code and I can't figure out what this does, or whether it is valid. The code is something like:

map<string, string> map;
map[string1] = ("s", string2);
like image 320
thrower Avatar asked Sep 24 '16 12:09

thrower


1 Answers

It's an obfuscation. The comma operator evaluates all the arguments from left to right but discards all arguments apart from the final one. The formal type of the entire expression is the type of the final argument.

(Note also that the comma itself is a sequencing point.)

string2 becomes the value in the map, under key string1.

like image 196
Bathsheba Avatar answered Oct 10 '22 04:10

Bathsheba