tracer.hpp 618 Bytes
Newer Older
Paul's avatar
Paul committed
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
36
37
38
39
40
41
42
43
44
#ifndef MIGRAPH_GUARD_RTGLIB_TRACER_HPP
#define MIGRAPH_GUARD_RTGLIB_TRACER_HPP

#include <ostream>

namespace migraph {

struct swallow
{
    template<class... Ts>
    swallow(Ts&&...)
    {}
};

struct tracer
{
    tracer()
    {}

    tracer(std::ostream& s) : os(&s)
    {}

    bool enabled() const
    {
        return os != nullptr;
    }

    template<class... Ts>
    void operator()(const Ts&... xs) const
    {
        if(os != nullptr) 
        {
            swallow{*os << xs...};
            *os << std::endl;
        }
    }

private:
    std::ostream * os = nullptr;
};

} // namespace migraph

#endif