123456789101112131415161718192021222324252627282930313233343536373839
#include <iostream> #include <cstring> #include <map> struct location { const char* file_name ; int line_number ; }; #define LOCATION() location{ __FILE__, __LINE__ } struct cmp_location { bool operator() ( const location& a, const location& b ) const { const auto result = std::strcmp( a.file_name, b.file_name ) ; if( result < 0 ) return true ; else if( result > 0 ) return false ; else return a.line_number < b.line_number ; } }; int main() { std::map< location, int, cmp_location > my_map ; my_map[ LOCATION() ] = 128 ; my_map[ LOCATION() ] = 229 ; my_map[ LOCATION() ] = 330 ; my_map[ LOCATION() ] = 532 ; for( const auto& [key,data] : my_map ) { std::cout << "key: { file:" << key.file_name << ", line:" << key.line_number << " } data: " << data << '\n' ; } }