
Filip Konvi?ka ha escrito:
JoaquÃn Mª López Muñoz (28.6.2007 9:49):
Filip Konvi?ka ha escrito: [...]
I use this template in my code:
template<typename T> struct get_pointer_to_member_details;
template<typename Class, typename Member> struct get_pointer_to_member_details<Member Class::*> { typedef Class class_type; typedef Member member_type; };
Using this, you can write (and I do) something like
template<typename MemberPointerType> struct member { MemberPointerType pMember; typedef typename get_pointer_to_member_details<MemberPointerType>::class_type class_type; typedef typename get_pointer_to_member_details<MemberPointerType>::member_type result_type;
member(MemberPointerType pMember) : pMember(pMember) {} // ... }
I wonder then, is it MSVC 8 that allows something non-standard, or is it OK? I think I tried with recent gcc as well and it worked...
Your code is fine, but it does not do what boost::multi_index::member is meant to do, namely accepting the pointer-to-member as a template parameter --rather, you're taking it as a runtime variable in construction time. Ah, I see...but duplicating the argument using a macro might work, like this:
#define MEMBER(MemPtr) member<get_details<MemPtr>::class_type, get_details<MemPtr>::member_type, MemPtr>
Umm... no, not quite so. MemPtr is a non-type parameter, so you'd have to write: #define MEMBER(MemPtr) \ member< \ get_details<decltype(MemPtr)>::class_type, \ get_details<decltype(MemPtr)>::member_type, \ MemPtr> So we have the need for a typeof-like facility agian :(
The reason why I think this is better is that when you change the member type in class declaration, you have to go through all member<> usages and change the type there too.
I agree with you having a macro like this makes usage simpler --but I haven't provided the macro because typeof or decltype is not standard and/or widely supported, and I don't know how to implement the macro without some of those. If you use GCC, which provides typeof(), then indeed you can write your private MEMBER utility in the manner described. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo