source.hpp

 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
#pragma once


#if __has_include(<source_location>)


#include <source_location>


namespace felspar {


    using source_location = std::source_location;


}


#elif __has_include(<experimental/source_location>)


#include <experimental/source_location>


namespace felspar {


    using source_location = std::experimental::source_location;


}


#else


namespace felspar {


    struct source_location {

Can't be consteval due to clang bug

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
        static /*consteval*/ constexpr source_location
                current(char const *f = __builtin_FILE(),
                        char const *fn = __builtin_FUNCTION(),
                        unsigned l = __builtin_LINE(),
                        unsigned c = __builtin_COLUMN()) noexcept {
            return {f, fn, l, c};
        }

        constexpr auto line() const noexcept { return l; }
        constexpr auto column() const noexcept { return c; }
        constexpr auto file_name() const noexcept { return f; }
        constexpr auto function_name() const noexcept { return fn; }

      private:
        constexpr source_location(
                char const *f, char const *fn, unsigned l, unsigned c)
        : f{f}, fn{fn}, l{l}, c{c} {}
        char const *f = {};
        char const *fn = {};
        unsigned l = {};
        unsigned c = {};
    };


}


#endif