summaryrefslogtreecommitdiff
path: root/source/fud_assert.cpp
blob: f3358df25b21f6f93c5e4c1c17f27f08399a4c78 (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
#include "fud_assert.hpp"

#include "fud_array.hpp"

#include <cstdio>
#include <stdexcept>
#include <format>

namespace fud {

void assertFail(const char* assertion, const char* file, unsigned int line, const char* function) noexcept(false)
{
    constexpr size_t ASSERT_MSG_SIZE = 1024;
    Array<char, ASSERT_MSG_SIZE> buffer{};
    static_cast<void>(std::format_to_n(
        buffer.data(),
        buffer.size() - 1U,
        "{}:{}: {}:Assertion `{}` failed",
        file,
        line,
        function,
        assertion));
    throw std::runtime_error(buffer.data());
}

}