home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,143 of 33,346   
   fmatthew5876 to All   
   cstring hash   
   24 Jul 13 23:51:37   
   
   From: fmatthew5876@googlemail.com   
      
   Simple question about hashing const char*.   
      
   I know that unordered_map treads char* like void* or any other pointer   
   and I agree with this. After all, we don't want to have more   
   vector like monstrosities.   
      
   My question is why couldn't the standard just provide a Hash class   
   for const char*, which anyone could explicitly use with   
   unordered_map/unordered_set if they wanted to.   
      
   For example:   
      
   namespace std {   
      
   struct cstr_hash {   
   //Same thing as std::string's hash function, no memory allocation   
   size_t operator()(const char* s) const;   
   };   
      
   }   
      
   And then we can do this if we want:   
   std::unordered_map map;   
      
   There is nothing wrong with the above. The third template parameter   
   tells the entire world that we are treating const char* in a special   
   way and in my opinion is totally acceptable.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca