Having good variables names is way more important than shortening the length of a line of code. Compromising the former for the sake of the later is not a good idea.
So if we don't want to touch the name of the variable, that leaves us with the name of the type. It's the main reason why the line of code is long in the first place anyways.
Type aliases are a good candidate here. You can use them to break things apart like so:
using float_map = std::unordered_map<std::string, float>;
using my_map = std::unordered_map<std::string, float_map>;
my_map variable_name;
Obviously, you should replace my_map
with a name that describes the purpose of the type in your code.
Also, if you use the same types multiple times, the aliases can be defined only once at the innermost scope that encompasses all uses:
namespace my_project {
using float_map = std::unordered_map<std::string, float>;
using my_map = std::unordered_map<std::string, float_map>;
void some_function() {
my_map variable_name;
// ...
}
class SomeClass {
my_map some_member_;
};
}