summaryrefslogtreecommitdiff
path: root/src/assert.hh
blob: a2b8cb7ba1b9a9eec7d9d828866ac230bb27c67c (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
#ifndef assert_hh_INCLUDED
#define assert_hh_INCLUDED

#include "exception.hh"

namespace Kakoune
{

struct assert_failed : logic_error
{
    assert_failed(const std::string& message);
    std::string description() const;

private:
    std::string m_message;
};

}

#define STRINGIFY(X) #X
#define TOSTRING(X) STRINGIFY(X)
#define COMMA ,

#ifdef assert
#undef assert
#endif

#define assert(condition) \
    if (not (condition)) \
        throw assert_failed("assert failed \"" #condition "\" at " __FILE__ ":" TOSTRING(__LINE__))

#endif // assert_hh_INCLUDED