I (and many other C++ programmers), on the other hand, I'm always annoyed and surprised that dictionaries on other languages do not have default insert on lookup.
It is just very convenient (hence the existence of defaultdict in python).
It is just very convenient (hence the existence of defaultdict in python).
if(auto i = x.find(y); i!=x.end()){
// use i->{first,second}
}
Also ideally you should be able to do this: for(auto [key, value]: x.equal_range(y)) {
}
But infuriatingly, x.equal_range returns a pair instead of some range view so you need some additional infrastructure (either convert the result of equal range into a range or add some begin/end overloads for pair).The equal_range solution looks nice from a genericity perspective (look ma I do multimaps!) but is really unintuitive with regular maps imo. Unless I'm mistaken it also does not allow an else branch for when the value is not there, which is often needed.
Hopefully one day we will get proper patter matching and destructing in if statements (Herb Sutter has made significant progress on this).
cpp2 is both interesting and ambitious, I really hope it gets somewhere.
OTOH, try...else I find myself missing at times.