Tuples in python are a reasonable tradeoff between not wanting to declare anything and the hassle of anonymous structure. This doesn't apply C++ where the equivalent is the POD struct:
//In the olden days we could not initialize a map inline like this
//Key -> metadata mapping. Unfortunately strutcts cannot be declared
//inside a template declaration.
struct TagData { int start; int length; StrToStr mapfun; };
const map TagDataMap {
{"title" , { 3, 30, stripnulls}},
{"artist" , { 33, 30, stripnulls}},
{"album" , { 63, 30, stripnulls}},
{"year" , { 93, 4, stripnulls}},
{"comment" , { 97, 29, stripnulls}},
{"genre" , {127, 1, ord}}};
Creating a named struct pays off when it's time to use the Map, no extra locals or tie() needed to write clear code: //for loops over collections are finally convenient to use.
for(auto td : TagDataMap){
//C++ created a horrible precedent by making the data type of
//a map pair instead of struct ValueType { K key; V value; };
auto tdd = td.second;
ret[td.first] = tdd.mapfun(sbuf.substr(tdd.start, tdd.length));
}
http://liveworkspace.org/code/bcd52515fb7161858e974b7ff3c0aa...