|
Boost Users : |
From: Filip KonviÄka (filip.konvicka_at_[hidden])
Date: 2007-06-28 04:13:00
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>
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.
So I guess I can define this macro if I want to use it :-)
Cheers,
Filip
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