Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind] [multi-index] Create type of pointer to overloaded erase method
From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2008-09-10 14:34:07


________________________________________
De: boost-users-bounces_at_[hidden] [boost-users-bounces_at_[hidden]] En nombre de Steven Watanabe [watanabesj_at_[hidden]]
Enviado el: miércoles, 10 de septiembre de 2008 18:54
Para: boost-users_at_[hidden]
Asunto: Re: [Boost-users] [bind] [multi-index] Create type of pointer to overloaded erase method

> AMDG
>
> Peter Barker wrote:
> > RecordsContainer::size_type (RecordsContainer::*erase)(unsigned int) =
> > &RecordsContainer::erase;
> >
> > but it failed to compile. Visual Studio 2003 gives me the following
> > error on the above line:
> > <snip>
> >
>
> The following compiles for me with msvc 9.0
>
> int main() {
> RecordsContainer::size_type (RecordsContainer::*erase)(unsigned int) =
> &RecordsContainer::erase;
> }

Oddly enough, it fails with MSVC++ 8.0 (though it shouldn't since your
call_traits analysis is correct):

error C2440: 'initializing' : cannot convert from 'overloaded-function' to
'boost::multi_index::detail::ordered_index<KeyFromValue,Compare,SuperMeta,
TagList,Category>::size_type (__thiscall
boost::multi_index::multi_index_container<Value,IndexSpecifierList>::* )(unsigned int)'
[...]

The following is bulletproof and has the added benefit of its immunity against
future slight changes in the interfaces (like, for instance, erase(key) getting
templatized):

  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;
  }

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