Quick Links:

bal | bbl | bdl | bsl

Namespaces | Defines

Component bslmf_memberfunctionpointertraits
[Package bslmf]

Provide meta-functions to detect member function pointer traits. More...

Namespaces

namespace  bslmf

Defines

#define bslmf_MemberFunctionPointerTraits   bslmf::MemberFunctionPointerTraits
#define bslmf_IsMemberFunctionPointer   bslmf::IsMemberFunctionPointer
#define bslmf_MemberFunctionPointerTraitsImp   bslmf::MemberFunctionPointerTraits_Imp

Detailed Description

Outline
Purpose:
Provide meta-functions to detect member function pointer traits.
Classes:
bslmf::MemberFunctionPointerTraits meta-function for detecting member
function pointer traits bslmf::IsMemberFunctionPointer: meta-function to determine if a type is a member function pointer
See also:
Component bslmf_functionpointertraits
Description:
This component provides meta-functions for determining the traits of a member function pointer. Two meta-functions are provided: bslmf::IsMemberFunctionPointer, and bslmf::MemberFunctionPointerTraits. bslmf::IsMemberFunctionPointer tests if a given type is a supported member function pointer. bslmf::MemberFunctionPointerTraits determines the traits of a member function type, including the type of the object that it is a member of, its result type, and the type of its list of arguments.
Note that, in order to support pre-C++11 compilers in a manageable way, only member functions with up to 14 arguments and no C-style (varargs) elipses are supported on all platforms by this component. When variadic templates are available, any number of arguments are supported. C-style elipses are not supported by this component at all. To identify all member function pointers see bslmf_ismemberfunctionpointer.
Usage:
Define the following function types:
  typedef void (*VoidFunc0)();
and the following struct with the following members:
  struct MyTestClass {
      static void voidFunc0() {}
      int func1(int) { return 0; }
      int func2(int, int) { return 1; }
  };
In order to deduce the types of voidFunc0 and func1, we will use the C++ template system to get two auxiliary functions:
  template <class t_TYPE>
  void checkNotMemberFunctionPointer(t_TYPE object)
  {
      assert(0 == bslmf::IsMemberFunctionPointer<t_TYPE>::value);
  }

  template <class t_BSLMF_RETURN, class t_ARGS, class t_TYPE>
  void checkMemberFunctionPointer(t_TYPE object)
  {
      assert(1 == bslmf::IsMemberFunctionPointer<t_TYPE>::value);
      typedef typename bslmf::MemberFunctionPointerTraits<t_TYPE>::ResultType
          ResultType;
      typedef typename
                     bslmf::MemberFunctionPointerTraits<t_TYPE>::ArgumentList
          ArgumentList;
      assert(1 == (bsl::is_same<ResultType, t_BSLMF_RETURN>::value));
      assert(1 == (bsl::is_same<ArgumentList, t_ARGS>::value));
  }
The following program should compile and run without errors:
  void usageExample()
  {
      assert(0 == bslmf::IsMemberFunctionPointer<int>::value);
      assert(0 == bslmf::IsMemberFunctionPointer<int>::value);

      checkNotMemberFunctionPointer(&MyTestClass::voidFunc0);
      checkMemberFunctionPointer<int, bslmf::TypeList1<int> >(
                                                        &MyTestClass::func1);
      checkMemberFunctionPointer<int, bslmf::TypeList2<int, int> >(
                                                        &MyTestClass::func2);
  }

Define Documentation

#define bslmf_MemberFunctionPointerTraits   bslmf::MemberFunctionPointerTraits
#define bslmf_IsMemberFunctionPointer   bslmf::IsMemberFunctionPointer
#define bslmf_MemberFunctionPointerTraitsImp   bslmf::MemberFunctionPointerTraits_Imp