tracer.hpp 663 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>
6
#include <migraph/config.hpp>
Paul's avatar
Paul committed
7

8
namespace migraph { inline namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
9
10
11

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

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

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

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

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

32
} // inline namespace MIGRAPH_INLINE_NS
Paul's avatar
Paul committed
33
34
35
} // namespace migraph

#endif