tracer.hpp 556 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
#ifndef MIGRAPH_GUARD_RTGLIB_TRACER_HPP
#define MIGRAPH_GUARD_RTGLIB_TRACER_HPP

#include <ostream>
Paul's avatar
Paul committed
5
#include <migraph/functional.hpp>
Paul's avatar
Paul committed
6
7
8
9
10

namespace migraph {

struct tracer
{
Paul's avatar
Paul committed
11
    tracer() {}
Paul's avatar
Paul committed
12

Paul's avatar
Paul committed
13
    tracer(std::ostream& s) : os(&s) {}
Paul's avatar
Paul committed
14

Paul's avatar
Paul committed
15
    bool enabled() const { return os != nullptr; }
Paul's avatar
Paul committed
16

Paul's avatar
Paul committed
17
    template <class... Ts>
Paul's avatar
Paul committed
18
19
    void operator()(const Ts&... xs) const
    {
Paul's avatar
Paul committed
20
        if(os != nullptr)
Paul's avatar
Paul committed
21
22
23
24
25
26
        {
            swallow{*os << xs...};
            *os << std::endl;
        }
    }

Paul's avatar
Paul committed
27
28
    private:
    std::ostream* os = nullptr;
Paul's avatar
Paul committed
29
30
31
32
33
};

} // namespace migraph

#endif