tags:

views:

296

answers:

2

I just came across this post and found a very elegant way of initializing maps

http://stackoverflow.com/questions/138600/initializing-a-static-stdmapint-int-in-c/1730798#1730798

So i wanted to start a thread in which we can list such idioms. They surely make you appreciate the power and expressiveness of C++

+2  A: 

check out boost.assign. it has even more assignment idioms using () and , operators. I am learning C++ myself and find boost to be excellent resource of what can be done with C++

aaa
Though boost assign is probably the only good reason I can think of for overloading the comma operator.
GMan
@GMan have you heard of the Blitz library? - that might provide other good reasons why one can overload the comma operator
Beh Tou Cheh
@Beh: That's mostly the same reason with a different name :)
GMan
how does blitz uses it? i looked at blitz cursorily, but instead decided to go with ublas, and possibly ftensor later on. blitz seemed little bit out of date
aaa
@unknown: Blitz uses it for assignment: `v = 1,2,3,4;`
GMan
A: 

Smart pointers in all flavours. Very common, but nevertheless a highly elegant idiom.

Alexander Gessler