"src/vscode:/vscode.git/clone" did not exist on "274c772b385003c4bef3bbe90b29de3dd2287dd7"
tracer.hpp 656 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
9
namespace migraph {
inline namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
10
11
12

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

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

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

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

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

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

#endif