summaryrefslogtreecommitdiffstats
path: root/lib/include/debug.hpp
blob: eed774c2c413ce4992918f6c28ee2c0959b1b974 (plain)
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
45
46
47
48
#pragma once

#ifdef DEBUG
#include <iostream>
#include <sstream>

#define __FILENAME__ (\
    __builtin_strrchr(__FILE__, '/') ? \
    __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)

#define npdebug(...); { \
    std::cerr << "[" << __FILENAME__ \
              << ":" << __LINE__ \
              << ", " << __func__ \
              << "] " ; \
    _np::debug(__VA_ARGS__); \
}

#define npinspect(msg, expr, ...); _np::inspect(msg, expr, __VA_ARGS__);

namespace _np {
    template<typename... Args>
    inline void debug(const Args&... args) {
        (std::cerr << ... << args) << std::endl;
    }

    template<typename Msg, typename Expr, typename... Args>
    inline Expr& inspect(const Msg& msg, Expr& expr, const Args&... args) {
        npdebug(msg, expr, args...);
        return expr;
    }
}

#else

#define npdebug(...); {}
#define npinspect(...); {}

namespace _np {
    template<typename.. Args>
    void debug(Args&... args) {}

    template<typename Msg, typename Expr, typename... Args>
    inline Expr& inspect(const Msg& msg, Expr& expr, const Args&... args) {
        return expr;
    }
}
#endif