Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind] [multi-index] Create type of pointer tooverloaded erase method
From: joaquin_at_[hidden]
Date: 2008-09-11 03:33:38


Peter Barker escribió:
> Both of the your solutions work in VC++ 2003 (7.1). I can understand
> your code above - you're going through the index to get at erase().
> The previous example I'm having a bit of trouble understanding
> though!:
>
> template<typename Container,typename Key>
> typename Container::size_type container_erase(Container& c,const Key& k)
> {
> return c.erase(k);
> }
>
> int main() {
> RecordsContainer::size_type (*erase)(RecordsContainer&,const unsigned int&) =
> &container_erase;
> }
>
> I've never seen a function template instantiated like this before. It
> appears to be deducing the template parameters based on the type it's
> assigning to. It looks very new to me and would like to understand a
> bit more.
>

The technique works exactly as you have described: if f<T1,...,Tn> is a
function template and you write

P *p=&f;

T1 and Tn are matched against the function type P (if possible). This is
explicitly stated in section
14.8.2.2 of the standard (if you don't have it grab a draft copy at
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf ).

HTH,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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