rob.hpp 1.34 KB
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPHX_GUARD_ROB_HPP
#define MIGRAPHX_GUARD_ROB_HPP
3
4
5
6
7
8
9
10
11
12

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

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

Paul's avatar
Paul committed
20
template <class Tag, typename Tag::type X>
21
22
struct stow_private
{
Paul's avatar
Paul committed
23
    stow_private() noexcept { stowed<Tag>::value = X; }
24
    // NOLINTNEXTLINE
Paul's avatar
Paul committed
25
    static stow_private instance;
26
};
Paul's avatar
Paul committed
27
template <class Tag, typename Tag::type X>
28
// NOLINTNEXTLINE
Paul's avatar
Paul committed
29
stow_private<Tag, X> stow_private<Tag, X>::instance;
30

Paul's avatar
Paul committed
31
32
33
template <class C, class T>
struct mem_data_ptr
{
Paul's avatar
Paul committed
34
    using type = T C::*;
Paul's avatar
Paul committed
35
};
36

Paul's avatar
Paul committed
37
// NOLINTNEXTLINE
Paul's avatar
Paul committed
38
#define MIGRAPHX_ROB(name, Type, C, mem)               \
Paul's avatar
Paul committed
39
40
41
42
43
44
45
46
47
    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;           \
    }
48
49
50
51
52
53

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif