fork download
  1. #include <map>
  2. #include <string>
  3.  
  4. struct referent_compare {
  5. template< typename t >
  6. bool operator () ( t *lhs, t *rhs )
  7. { return * lhs < * rhs; }
  8. };
  9.  
  10. template< typename t >
  11. t const *temp_ptr( t const &o ) { return &o; }
  12.  
  13. struct s {
  14. std::string name;
  15. long birthdate;
  16. double score;
  17. };
  18.  
  19. std::map< std::string const *, s, referent_compare > byname;
  20. std::map< double const *, s, referent_compare > byscore;
  21.  
  22. int main() {
  23. s bob = { "bob", 12000000, 96.3 };
  24. byname.insert( std::make_pair( & bob.name, bob ) );
  25. byscore.insert( std::make_pair( & bob.score, bob ) );
  26.  
  27. byname[ temp_ptr< std::string >( "bob" ) ].score = 33.1;
  28. }
  29.  
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
Standard output is empty