|
Prev: std::deque typically faster then std::list for push_back(), front(), pop_front()?
Next: std::deque typically faster then std::list for push_back(), front(), pop_front()?
From: Bart van Ingen Schenau on 11 Jan 2008 10:58 cppcraze wrote: > Hi, > > Since loki help forum is not responded timely, I would like to ask a > simple question here about Int2Type defined by Mr Alexandrescu. > Following is definition of Int2Type: > > template<int v> > struct Int2Type > { > enum { value = v }; > }; > > My question is: is the enumeration inside above struct necessary? I > have tested the version with the enum removed and it also works, i.e. > it can also do the compile-time dispatch according some compile-time > integer. So why the enum is there? Is there any other consideration I > missed? The enum is not needed to make the template work. But if you ever need to access the value that the type was created with, you need the enum (or a similar, less convenient, mechanism) to do so. So, the enum exists primarily to enable a reverse mapping from Int2Type back to int. > > Thanks, > > Martin > Bart v Ingen Schenau -- a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq c.l.c FAQ: http://c-faq.com/ c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/ [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |