-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract-member.cc
35 lines (30 loc) · 999 Bytes
/
extract-member.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
template <class Struct, class Member>
Struct deduce_memptr_struct_type(Member Struct::*);
template <class Struct, class Member>
Member deduce_memptr_member_type(Member Struct::*);
template <class Struct, class Member, Member Struct::* memptr>
struct extract_member_t_static {
constexpr Member operator()(Struct s) const
{
return s.*memptr;
}
};
#define extract_member_static(memptr) \
extract_member_t_static \
<decltype(deduce_memptr_struct_type(memptr)), \
decltype(deduce_memptr_member_type(memptr)), \
memptr>()
template <class Struct, class Member>
struct extract_member_t_dynamic {
Member Struct::* memptr;
constexpr Member operator()(Struct s) const
{
return s.*memptr;
}
};
template <class Struct, class Member>
extract_member_t_dynamic<Struct, Member>
extract_member_dynamic(Member Struct::* memptr)
{
return { memptr };
}