Boost logo

Boost :

Subject: Re: [boost] [introspection] Status
From: Richard Hazlewood (boost_at_[hidden])
Date: 2009-07-22 05:28:29


joel <joel.falcou <at> lri.fr> writes:

>
> Richard Hazlewood wrote:
> > I see the vault contains some introspection helpers (for checking for
member
> I wish but there is still a substantial amoutn of work on them to make
> them work properly on MSVC.

I'm currently tied to MSVC7.1, and they appear to work okay with that. Is
there a problem with a particular version?

I've actually been looking for a way to check for: does (or, perhaps can)
template function exist in type.

I've been experimenting with modifying your macro, so that the signature
becomes a template argument. E.g. so code such as:

  template <typename R, typename X>
  void foo()
  {
    bool const has = has_non_const_member_function_bar<X, R (*)()>::value;
    ...
  }

  struct X
  {
    template <typename T>
    T bar();
  };

  foo<int, X>();

Could be made to work.

Trying:

1] #define BOOST_HAS_NON_CONST_MEMBER_FUNCTION(Name,Sig) \
2] namespace boost \
3] { \
4] namespace introspection \
5] { \
6] template<class T, class F = Sig> \
7] struct BOOST_PP_CAT(has_non_const_member_function_,Name) \
8] { \
9] typedef char NotFound; \
A] struct Found { char x[2]; }; \
B] \
C] template< typename build_member_type<T,F>::type \
D] > struct member {}; \
E] \
F] template<class X> static Found test(member<&X::Name>*); \
G] template<class X> static NotFound test( ... ); \
H] \
I] static const bool value = (sizeof(Found) == sizeof(test<T>(0))); \
J] typedef mpl::bool_<value> type; \
K] }; \
L] } \
M] } \
/**/

However, it doesn't appear to work (at least in VC71). It looks like the
sizeof trick is not capable of stamping out the template function.

Do you know if this can be achieved?

Note: Lines [C-D, F] were modified from:

      template< class X \
              , typename build_const_member_type<X,F>::type \
> struct member {};

      template<class X> static Found test(X, member<&X::Name>*); \

Because VC71 would not compile it that way when Sig was a template arg (F).
[shrug].

This didn't seem to affect the original behaviour, was there a reason for it?

> > (There appears to be an overlap with some of the introspection utils in
mpl -
> Overlaps with ? MPL has check for inner type existence that's all no ?

Yes, 'overlap' was a poor choice of word; I probably meant association, but, as
you say, it's closer to type_traits.

Regards...


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk