Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Member Pointer Features

apply_member_pointer
parent_class_of
qualified_parent_class_of
Header
#include <boost/callable_traits/apply_member_pointer.hpp>
Definition
template<typename T, typename C>
using apply_member_pointer_t = //implementation-defined

template<typename T, typename C>
struct apply_member_pointer {
    using type = apply_member_pointer_t<T, C>;
};
Constraints
  • T may be any type except void
  • C must be a user-defined type
Behavior
  • A substitution failure occurs if the constraints are violated.
  • When T is a function, function pointer, or function reference, then the aliased type is a member function pointer of C with the same parameters and return type.
  • When T is a member function pointer of any type, the aliased type is a member function pointer of C with the same parameters and return type.
  • Otherwise, the aliased type is a member data pointer equivalent to std::remove_reference_t<T> C::*.
Compatibility Notes

Full support on GCC 4.7.4+, Clang 3.5+, Visual Studio 2015, and XCode 6.4+.

Input/Output Examples

T

apply_member_pointer_t<T, foo>

int()

int(foo::*)()

int (&)()

int(foo::*)()

int (*)()

int(foo::*)()

int(bar::*)()

int(foo::*)()

int(bar::*)() &

int(foo::*)() &

int(bar::*)() &&

int(foo::*)() &&

int(bar::*)() const

int(foo::*)() const

int(bar::*)() transaction_safe

int(foo::*)() transaction_safe

int bar::*

int foo::*

int

int foo::*

int &

int foo::*

const int &

const int foo::*

int (*const)()

int (*const foo::*)()

void

(substitution failure)

Example Program
#include <type_traits>
#include <boost/callable_traits/apply_member_pointer.hpp>

namespace ct = boost::callable_traits;

struct foo;
struct bar;

int main() {

    {
        // function type -> member function pointer type
        using f = int(int);
        using g = ct::apply_member_pointer_t<f, foo>;
        using expect = int(foo::*)(int);
        static_assert(std::is_same<g, expect>::value, "");
    }

    {
        // function pointer type (unqualified) -> member function pointer type
        using f = int(*)();
        using g = ct::apply_member_pointer_t<f, foo>;
        using expect = int(foo::*)();
        static_assert(std::is_same<g, expect>::value, "");
    }


    {
        // function pointer type (qualified) -> member data pointer type

        // Look out for cases like these two. If the input type to apply_member_pointer
        // is a qualified function pointer type, then the  aliased type is a member data
        // pointer to a qualified function pointer.

        {
            using f = int(*&)();
            using g = ct::apply_member_pointer_t<f, foo>;
            using expect = int (* foo::*)();
            static_assert(std::is_same<g, expect>::value, "");
        }

        {
            using f = int(* const)();
            using g = ct::apply_member_pointer_t<f, foo>;
            using expect = int (* const foo::*)();
            static_assert(std::is_same<g, expect>::value, "");
        }
    }

    {
        // function reference type -> member function pointer type
        using f = void(&)();
        using g = ct::apply_member_pointer_t<f, foo>;
        using expect = void(foo::*)();
        static_assert(std::is_same<g, expect>::value, "");
    }

    {
        // member function pointer type -> member function pointer type
        // (note the different parent class)
        using f = int(bar::*)() const;
        using g = ct::apply_member_pointer_t<f, foo>;
        using expect = int(foo::*)() const;
        static_assert(std::is_same<g, expect>::value, "");
    }

    {
        // non-callable type -> member data pointer type
        using g = ct::apply_member_pointer_t<int, foo>;
        using expect = int foo::*;
        static_assert(std::is_same<g, expect>::value, "");
    }


    {
        // function object type -> member data pointer type
        // the same is true for lambdas and generic lambdas
        auto lambda = [](){};
        using f = decltype(lambda);
        using g = ct::apply_member_pointer_t<f, foo>;
        using expect = f foo::*;
        static_assert(std::is_same<g, expect>::value, "");
    }
}
Header
#include <boost/callable_traits/parent_class_of.hpp>
Definition
template<typename T>
using parent_class_of_t = //implementation-defined

template<typename T>
struct parent_class_of {
    using type = parent_class_of_t<T>;
};
Constraints
  • T must be a member pointer
Behavior
  • A substitution failure occurs if the constraints are violated.
  • The aliased type is the parent class of the member. In other words, if T is expanded to U C::*, the aliased type is C.
Compatibility Notes

Full support on GCC 4.7.4+, Clang 3.5+, Visual Studio 2015, and XCode 6.4+.

Input/Output Examples

T

parent_class_of_t<T>

int foo::*

foo

void(foo::*)() const

foo

Example Program
#include <type_traits>
#include <boost/callable_traits/parent_class_of.hpp>

namespace ct = boost::callable_traits;

struct foo;

static_assert(std::is_same<foo, ct::parent_class_of_t<int(foo::*)()>>::value, "");
static_assert(std::is_same<foo, ct::parent_class_of_t<int foo::*>>::value, "");

int main() {}
Header
#include <boost/callable_traits/qualified_parent_class_of.hpp>
Definition
template<typename T>
using qualified_parent_class_of_t = //implementation-defined

template<typename T>
struct qualified_parent_class_of {
    using type = qualified_parent_class_of_t<T>;
};
Constraints
  • T must be a member pointer
Behavior
  • A substitution failure occurs if the constraints are violated.
  • If T is a member function pointer, the aliased type is the parent class of the member, qualified according to the member qualifiers on T. If T does not have a member reference qualifier, then the aliased type will be an lvalue reference.
  • If T is a member data pointer, the aliased type is equivalent to ct::parent_class_of<T> const &.
Compatibility Notes

Full support on GCC 4.7.4+, Clang 3.5+, Visual Studio 2015, and XCode 6.4+.

Input/Output Examples

T

qualified_parent_class_of_t<T>

void(foo::*)()

foo &

void(foo::*)() const

foo const &

void(foo::*)() &&

foo &&

void(foo::*)() volatile &&

foo volatile &&

int foo::*

foo const &

const int foo::*

foo const &

Example Program
#include <type_traits>
#include <boost/callable_traits/qualified_parent_class_of.hpp>

namespace ct = boost::callable_traits;

struct foo;

static_assert(std::is_same<foo &,
    ct::qualified_parent_class_of_t<int(foo::*)()>>::value, "");

static_assert(std::is_same<foo const &,
    ct::qualified_parent_class_of_t<int(foo::*)() const>>::value, "");

static_assert(std::is_same<foo volatile &&,
    ct::qualified_parent_class_of_t<int(foo::*)() volatile &&>>::value, "");

int main() {}

PrevUpHomeNext