Re: How to convert a pointer to member function type to a const member one
  Home FAQ Contact Sign in
comp.lang.c++.moderated only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: How to convert a pointer to member function type to a const member one         

Group: comp.lang.c++.moderated · Group Profile
Author: mcostalba
Date: May 6, 2008 11:14

On 6 Mag, 16:21, "Roman.Perepeli...@gmail.com"
gmail.com> wrote:
>
>
> Alexandre Courpron modified is_call_possible to create
> is_exact_call_possible. You can find implementation here:http://groups.google.co.uk/group/comp.lang.c++.moderated/browse_threa...

I have quickly checked the link and it surely deserves a deeper read
when I found a bit of time.

Anyhow here is my much simpler solution...so simple that is probably
broken in some way, but I cannot find where:

/* Check if a function/functor Fun has a given signature Sig */
template
struct is_compatible
{
typedef typename boost::remove_pointer::type F;

/* Build pointer_to_member types from the given signature */
typedef typename pointer_to_member::value, F,
Sig>::type ptm;
typedef typename pointer_to_member::value, F,
Sig>::const_type ptm_const;

/* Check for a function */
template static
yes_type detect(typename enable_if >::type*);

/* Check for a functor, either const and non-const members are
detected */
template struct helper;
template struct helper_const;

template static
yes_type detect(helper<&U::operator()>*);

template static
yes_type detect(helper_const<&U::operator()>*);

/* Default */
template static
no_type detect(...);

static const bool
value = (sizeof(detect(0)) == sizeof(yes_type));
};

Where template pointer_to_member<> is:

/* Convert a signature type Sig to a pointer_to_member type */
template
struct pointer_to_member;

template
struct pointer_to_member<1, T, Sig> // filter out function types
{
typedef int type;
typedef int const_type;
};

template
struct pointer_to_member<0, T, R()>
{
typedef R(T::* type) ();
typedef R(T::* const_type)() const;
};

template
struct pointer_to_member<0, T, R(A0)>
{
typedef R(T::* type)(A0);
typedef R(T::* const_type)(A0) const;
};

...... and so on for each argument arity ........

BTW it seems to work.

Thanks
Marco

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
Re: To convert or not to convert, that's the questioncomp.lang.clipper.visual-objects ·