std::map uses a comparator to check if a key exists or not. Therefore, when you use std::tm , you should also provide a comparative example as the third argument.
template < class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key,T> > > class map
So the solution will be a functor (you guessed it):
struct tm_comparer { bool operator () (const std::tm & t1, const std::tm & t2) const {
Or define a free function ( operator < ) as:
bool operator < (const std::tm & t1, const std::tm & t2) { // ^ note this. Now its less than operator //compare t1 and t2, and return true/false }; std::map<std::tm, std::string> mapItem; //no need to pass any argument now!
Nawaz source share