Annamalai Gurusami
Hi All, http://www.boost.org/doc/libs/1_36_0/libs/multi_index/doc/index.html [...] I am trying to understand what is the use of the identity<> template class. I also noticed the following in the documentation, "The predefined identity predicate can be used here as a key extractor; identity returns as the key the same object passed as argument." Is there any reason why the word object (instead of type) is used in that sentence? Also if the identity<> template evaluates to the type given as its argument, is there any benefit out of it?
I *think* I know where your confusion stems from: identity<> is not a purely compile-time entity as some MPL constructs are, but a conventional type with real run-time functionality (I guess you are wondering why not use T directly instead of identity<T>, right?): 1. Is there any reason why the word object (instead of type) is used in that sentence? Because identity<T> operates at run time as a functor taking objects of type T: identitystd::string i; std::string str="hello"; std::cout< template evaluates to the type given as its argument, is there any benefit out of it? identity<T> does not evaluate to T, as said before it is not a MPL metafunction but a plain functor much as, for instance, std::less<> or boost::hash<>. Clearer now? Don't hesitate to come back if doubts persist. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo