]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/callable_traits/example/apply_member_pointer.cpp
2 Copyright (c) 2016 Barrett Adair
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8 //[ apply_member_pointer
10 #include <boost/callable_traits/apply_member_pointer.hpp>
12 namespace ct
= boost::callable_traits
;
20 // function type -> member function pointer type
22 using g
= ct::apply_member_pointer_t
<f
, foo
>;
23 using expect
= int(foo::*)(int);
24 static_assert(std::is_same
<g
, expect
>::value
, "");
28 // function pointer type (unqualified) -> member function pointer type
30 using g
= ct::apply_member_pointer_t
<f
, foo
>;
31 using expect
= int(foo::*)();
32 static_assert(std::is_same
<g
, expect
>::value
, "");
37 // function pointer type (qualified) -> member data pointer type
39 // Look out for cases like these two. If the input type to apply_member_pointer
40 // is a ``[*qualified]`` function pointer type, then the aliased type is a member data
41 // pointer to a ``[*qualified function pointer]``.
45 using g
= ct::apply_member_pointer_t
<f
, foo
>;
46 using expect
= int (* foo::*)();
47 static_assert(std::is_same
<g
, expect
>::value
, "");
51 using f
= int(* const)();
52 using g
= ct::apply_member_pointer_t
<f
, foo
>;
53 using expect
= int (* const foo::*)();
54 static_assert(std::is_same
<g
, expect
>::value
, "");
59 // function reference type -> member function pointer type
61 using g
= ct::apply_member_pointer_t
<f
, foo
>;
62 using expect
= void(foo::*)();
63 static_assert(std::is_same
<g
, expect
>::value
, "");
67 // member function pointer type -> member function pointer type
68 // (note the different parent class)
69 using f
= int(bar::*)() const;
70 using g
= ct::apply_member_pointer_t
<f
, foo
>;
71 using expect
= int(foo::*)() const;
72 static_assert(std::is_same
<g
, expect
>::value
, "");
76 // non-callable type -> member data pointer type
77 using g
= ct::apply_member_pointer_t
<int, foo
>;
78 using expect
= int foo::*;
79 static_assert(std::is_same
<g
, expect
>::value
, "");
84 // function object type -> member data pointer type
85 // the same is true for lambdas and generic lambdas
87 using f
= decltype(lambda
);
88 using g
= ct::apply_member_pointer_t
<f
, foo
>;
89 using expect
= f
foo::*;
90 static_assert(std::is_same
<g
, expect
>::value
, "");