[TypeTraits] Type traits for member pointers?

I recently noticed that the Boost Type Traits library does not include any traits for member pointers apart from identification. For example, there are no "add member pointer" or "remove member pointer" traits, nor a trait to extract the containing type from a member pointer (ie extract Q from T Q::*). And there is no trait for decomposing member function pointers. It would appear that these traits could be added fairly easily; I was able to create them within a few minutes, and verify that they worked (with g++). Is there sufficient reason to add them to the library? For me, completeness seems like reason enough (unless it would be a lot of work). On the other hand, member pointers are, as far as I know, rarely used. So, um... thoughts? Is it a good idea? Should I post my code? --SPCD "Celtic Minstrel"

I recently noticed that the Boost Type Traits library does not include any traits for member pointers apart from identification. For example, there are no "add member pointer" or "remove member pointer" traits, nor a trait to extract the containing type from a member pointer (ie extract Q from T Q::*). And there is no trait for decomposing member function pointers.
It would appear that these traits could be added fairly easily; I was able to create them within a few minutes, and verify that they worked (with g++). Is there sufficient reason to add them to the library? For me, completeness seems like reason enough (unless it would be a lot of work). On the other hand, member pointers are, as far as I know, rarely used.
So, um... thoughts? Is it a good idea? Should I post my code?
It's been asked for before: https://svn.boost.org/trac/boost/ticket/2011, and there's some start on this in the sandbox - see https://svn.boost.org/trac/boost/browser/sandbox/type_traits/boost/type_trai... - however there was no general agreement over nomenclature last time this was raised, which is largely why this is stalled - that and a lack of time on my part :-( John.

see https://svn.boost.org/trac/boost/browser/sandbox/type_traits/boost/type_trai... That looks good...
- however there was no general agreement over nomenclature last time this was raised, What sort of disagreement?
Anyway, that only satisfies one of the four things I mentioned – unless I'm misreading it, it is a template to extract Q from "T Q::*". What about an add_member_ptr, and a remove_member_ptr? So, add_member_ptr<int,Q>::type would be int Q::*, and remove_member_ptr<int Q::*>::type would be int. And there's also no trait for decomposing member functions in the vein of function_traits. I think it could probably be implemented almost identically to the existing function_traits template, but with the addition of another member type which is basically member_pointer<T>::type. Another idea is something the checks if a member function is const or volatile, though that could be done with a combination of is_const or is_volatile with member_pointer. Just wondering, why is it necessary to specialize member_pointer for member function types? After all, in a type "T Q::*" the T could be a function type "void(int)", which would make the full type "void(Q::*)(int)", right? --SPCD "Celtic Minstrel"

AMDG Celtic Minstrel wrote:
Just wondering, why is it necessary to specialize member_pointer for member function types? After all, in a type "T Q::*" the T could be a function type "void(int)", which would make the full type "void(Q::*)(int)", right?
void (Q::*)(int) const is a legal type. void(int) const is not. In Christ, Steven Watanabe

Celtic Minstrel wrote:
I recently noticed that the Boost Type Traits library does not include any traits for member pointers apart from identification. For example, there are no "add member pointer" or "remove member pointer" traits, nor a trait to extract the containing type from a member pointer (ie extract Q from T Q::*). And there is no trait for decomposing member function pointers.
As far as decomposing member function pointers, is http://www.boost.org/doc/libs/1_39_0/libs/function_types/doc/html/index.html what you're looking for? - Jeff

On Fri, Jul 17, 2009 at 2:55 PM, Steven Watanabe<watanabesj@gmail.com> wrote:
void (Q::*)(int) const is a legal type. void(int) const is not.
Ah yes, that's true. Still, wouldn't it work just as well if it were specialized for cv-qualified member function types but not for the cv-unqualified form? On Fri, Jul 17, 2009 at 3:02 PM, Jeffrey Hellrung<jhellrung@ucla.edu> wrote:
As far as decomposing member function pointers, is http://www.boost.org/doc/libs/1_39_0/libs/function_types/doc/html/index.html what you're looking for?
Apparently. Thanks. I have no idea how I missed that. I think I even looked at that page awhile ago, actually... (Is that intended to replace the function_traits template in the TypeTraits library?) Anyway, I'd like to point out that the member_object.hpp header linked to by John Maddock is not actually what the tracking ticket he also linked to was asking for. It seems pretty clear to me that whoever posted that wanted something more like this: template<class T> struct remove_mem_ptr { typedef T type; }; template<class T, class In> struct remove_mem_ptr<T In::*> { typedef T type; }; template<class T, class In> struct add_mem_ptr { typedef T In::*type; }; // (for completeness...) (Evidence: the person who posted that ticket said this:
Can boost::remove_pointer<T> be modified to work with pointers-to-member (data), too? For instance: remove_pointer<int *> returns the int type, but so should remove_pointer<int std::div_t::*>. ...implying that he wants remove_pointer<int std::div_t::*> to return int, not std::div_t. And member_object<int std::div_t::*> would return std::div_t.)
--SPCD "Celtic Minstrel"

Anyway, I'd like to point out that the member_object.hpp header linked to by John Maddock is not actually what the tracking ticket he also linked to was asking for. It seems pretty clear to me that whoever posted that wanted something more like this:
template<class T> struct remove_mem_ptr { typedef T type; }; template<class T, class In> struct remove_mem_ptr<T In::*> { typedef T type; };
template<class T, class In> struct add_mem_ptr { typedef T In::*type; }; // (for completeness...)
(Evidence: the person who posted that ticket said this:
Can boost::remove_pointer<T> be modified to work with pointers-to-member (data), too? For instance: remove_pointer<int *> returns the int type, but so should remove_pointer<int std::div_t::*>. ...implying that he wants remove_pointer<int std::div_t::*> to return int, not std::div_t. And member_object<int std::div_t::*> would return std::div_t.)
Not quite, there was some discussion on the mailing list about that feature request (including with the OP) and there was a clear consensus for *not* modifying remove_pointer, but for adding a new trait (which the OP was happy with as far as I recall). The reason for not using the "obvious simple implementation" BTW is two fold: * It doesn't work for all compilers. * It doesn't handle compiler extensions like __fastcall etc. HTH, John.

On Mon, Jul 20, 2009 at 7:31 AM, John Maddock<john@johnmaddock.co.uk> wrote:
Not quite, there was some discussion on the mailing list about that feature request (including with the OP) and there was a clear consensus for *not* modifying remove_pointer, but for adding a new trait (which the OP was happy with as far as I recall). Yes, the original post also included something along the lines of "or add a new trait". My point was only that member_pointer did not satisfy his request.
On Mon, Jul 20, 2009 at 7:31 AM, John Maddock<john@johnmaddock.co.uk> wrote:
The reason for not using the "obvious simple implementation" BTW is two fold:
* It doesn't work for all compilers. * It doesn't handle compiler extensions like __fastcall etc. Yeah, judging by other Boost libraries I knew that the simple form is not enough due to the need for workarounds.
--SPCD "Celtic Minstrel"
participants (4)
-
Celtic Minstrel
-
Jeffrey Hellrung
-
John Maddock
-
Steven Watanabe