Boost logo

Boost Users :

Subject: [Boost-users] Purpose of identity template
From: Annamalai Gurusami (annamalai.gurusami_at_[hidden])
Date: 2008-09-04 14:47:11


Hi All,

I have been going through the documentation of the
multi_index_container in the Boot.MultiIndex library. In the example
code provided I saw the use of the identity<> template. The relevant
portion of the example code is reproduced here for convenience.

http://www.boost.org/doc/libs/1_36_0/libs/multi_index/doc/index.html

typedef multi_index_container<
  employee,
  indexed_by<
    // sort by employee::operator<
    ordered_unique<identity<employee> >,

    // sort by less<string> on name
    ordered_non_unique<member<employee,std::string,&employee::name> >
>
> employee_set;

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 am quite new to template meta programming and am trying to
understand things. Any explanation would be very helpful.

Rgds,
anna

-- 
Abusive Language on Internet
http://missingrainbow.blogspot.com/2008/08/abusive-language-on-internet.html

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net