C++ patterns
Functional, Minimalistic and Useful C++ Map-Like Container
Perfect map-based accumulator & converter in C++
Welcome to the first of my planned series about interesting C++ patterns and architectural solutions. And the first question is: what do you associate with the phrase “C++ patterns”? For me, it is the famous “Band of four” book about code patterns design, by Gamma, Helm, Vlissides, and Johnson. And it inspired me to search, recreate, apply and reuse new solutions that were never described in that book. So, there will be no word about any pattern from the mentioned book, but only personal research and code probes.
If you look at a random C++ library or project, there are great chances to find some hand-made containers. We won’t talk about the purposes of such random containers, it is obvious, that they vary a lot. Instead, let’s look closely at the map-like ones.
They are very simple: key and value, key and structure, key and some action. Simple in usage, but there is one keystone — the initialization of the structure. You may have seen long lists of append
method calls, obfuscated initialization lists, complex constructors, etc. But one time something different has caught my eye. It was boost::assign
type of map initialization. It is compact and neat, so I decided to…