Re: [Boost-users] [bind] [multi-index] Create type of pointer to overloaded erase method
________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de JOAQUIN M. LOPEZ MUÑOZ [joaquin@tid.es] Enviado el: miércoles, 10 de septiembre de 2008 20:34 Para: boost-users@lists.boost.org Asunto: Re: [Boost-users] [bind] [multi-index] Create type of pointer to overloaded erase method
________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de Steven Watanabe [watanabesj@gmail.com] Enviado el: miércoles, 10 de septiembre de 2008 18:54 Para: boost-users@lists.boost.org 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
::size_type (__thiscall boost::multi_index::multi_index_container ::* )(unsigned int)'
But the following works: int main() { typedef RecordsContainer::index<RecsByID>::type RecordsContainerByID; RecordsContainerByID::size_type (RecordsContainerByID::*erase)(unsigned int) = &RecordsContainerByID::erase; } even though my previous approach is IMHO still better. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
On Wed, Sep 10, 2008 at 7:43 PM, JOAQUIN M. LOPEZ MUÑOZ
________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de JOAQUIN M. LOPEZ MUÑOZ [joaquin@tid.es] Enviado el: miércoles, 10 de septiembre de 2008 20:34 Para: boost-users@lists.boost.org Asunto: Re: [Boost-users] [bind] [multi-index] Create type of pointer to overloaded erase method
________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de Steven Watanabe [watanabesj@gmail.com] Enviado el: miércoles, 10 de septiembre de 2008 18:54 Para: boost-users@lists.boost.org 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
::size_type (__thiscall boost::multi_index::multi_index_container ::* )(unsigned int)' But the following works:
int main() { typedef RecordsContainer::index<RecsByID>::type RecordsContainerByID; RecordsContainerByID::size_type (RecordsContainerByID::*erase)(unsigned int) = &RecordsContainerByID::erase; }
even though my previous approach is IMHO still better.
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
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::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
The technique works exactly as you have described: if f
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,
It does a lot - thank you! And by the way, multi-index container has made my code a lot smaller, neater, more readable and more exception safe, so thanks for that too!
participants (3)
-
JOAQUIN M. LOPEZ MUÑOZ
-
joaquin@tid.es
-
Peter Barker