Easier comparison operators with std::tie

Being able to arbitrarily ‘look up’ or fetch an element from a collection is a critical tool in almost all C++ applications – or any programming language, for that matter.  Typically, in C++, this common paradigm manifests through the use of an std::map<TKey, TItem>  or an std::unordered_map<TKey, TItem> .  When your lookup ‘key’ is a simple, built-in type – such as an enum, int or string – everything just ‘works,’ because those simple types have built-in comparison operators.

Trivial keys can have limited usefulness, however.  More often than not, we need more complex lookup keys, in the form of aggregate types.  This post describes some tricks you can use to easily create aggregate types and reduce boilerplate code. Continue reading “Easier comparison operators with std::tie”