
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