vishesh
Nearly a Posting Virtuoso
1,381 posts since Oct 2006
Reputation Points: 85
Solved Threads: 42
it is a standard component of the library in c++0x see http://www.open-std.org/jtc1/sc22/wg21/ libstdc++ (gcc 4.30) and dinkumware std c++ library implement this natively; boost.tr1 library could be used if you have an older compiler and boost.
#include <iostream>
#include <functional>
int main( int argc, char** argv )
{
//using libstdc++ TR1 implementation (g++43 -std=c++0x)
std::cout << std::hash<char*>()( argv[0] ) << '\n' ;
//using boost.tr1 library ( #include <boost/tr1/functional.hpp> )
//std::cout << std::tr1::hash<char*>()( argv[0] ) << '\n' ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
while going thru STL I came to know something knows as functors. Thought I understood what practically it is but still could not make out it's advantage and usage. Could anybody throw some light over it. I need to know in detail about it.
This isn't related to hash, hope you know that. Ideally creation of a new thread for a new topic is helpful for everyone (rather than e.g. discussing all STL doubts in one thread).
See this link for description of functors AKA function objects or functionoid.
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
Just use a std::map. You hear me? A std::map. Do you have any good reason to do otherwise? You're probably overestimating the importance of the log n time factor (which hash tables usually still have, albeit in a hidden manner). Of course, maybe you really can't use a std::map for some reason. But I don't see why.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177