rob.hpp 1.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef MIGRAPH_GUARD_ROB_HPP
#define MIGRAPH_GUARD_ROB_HPP

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif

// Used to access private member variables
template <class Tag>
struct stowed
{
Paul's avatar
Paul committed
13
14
15
    static typename Tag::type value;
};
template <class Tag>
16
17
18
19
20
typename Tag::type stowed<Tag>::value;

template <class Tag, typename Tag::type x>
struct stow_private
{
Paul's avatar
Paul committed
21
22
    stow_private() { stowed<Tag>::value = x; }
    static stow_private instance;
23
};
Paul's avatar
Paul committed
24
25
template <class Tag, typename Tag::type x>
stow_private<Tag, x> stow_private<Tag, x>::instance;
26

Paul's avatar
Paul committed
27
28
29
30
31
template <class C, class T>
struct mem_data_ptr
{
    typedef T(C::*type);
};
32

Paul's avatar
Paul committed
33
34
35
36
37
38
39
40
41
42
#define MIGRAPH_ROB(name, Type, C, mem)                \
    struct name##_tag : mem_data_ptr<C, Type>          \
    {                                                  \
    };                                                 \
    template struct stow_private<name##_tag, &C::mem>; \
    template <class T>                                 \
    auto& name(T&& x)                                  \
    {                                                  \
        return x.*stowed<name##_tag>::value;           \
    }
43
44
45
46
47
48

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif