Annamalai Gurusami escribió:
Thank you very much for the response. Now I understand that identity<> is not an MPL construct. I was reading through the identity.hpp file and I think I understand it now. It can be used to convert chained pointers and smart pointers to references. For example,
int ****i; identity<int> get_ref; get_ref(i); // This will return me a reference to the integer
Let me know if I got that right.
Correct. You hopefully don't need to read the code directly to learn that, as is explained at http://www.boost.org/libs/multi_index/doc/tutorial/key_extraction.html http://www.boost.org/libs/multi_index/doc/reference/key_extraction.html
But since the template arguments are type names is there any reason why we need to use identity in template arguments? For example, in the code snippet given in the documentation, (my question embedded in the code fragment below as comments),
typedef multi_index_container< employee, indexed_by< ordered_unique
, // Why is identity required here? // Why is ordered_unique<employee> not sufficient? ordered_non_unique >, ordered_unique > employee_set;
Since the std::set doesn't require anything other than the type name of the elements it would hold, why does boost::multi_index::ordered_unique need this identity<>? What are the additional benefits of this added complexity?
STL associative containers like std::set and std::map use the notion of
a key associated to a
value, although they do so in an implicit manner:
set<T> --> value_type=T, key_type=T
map