Line data Source code
1 : #pragma once 2 : 3 : #include <iostream> 4 : 5 : // Based on the standard paper P0627r0 (see 6 : // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0627r0.pdf) 7 : #if defined(_MSC_VER) 8 : #define ELSA_UNREACHABLE() __assume(false); 9 : #elif defined(__GNUC__) or defined(__clang__) 10 : // All gcc/clang compilers supporting c++17 have __builtin_unreachable 11 : #define ELSA_UNREACHABLE() __builtin_unreachable() 12 : #else 13 : #include <exception> 14 : #define ELSA_UNREACHABLE() std::terminate() 15 : #endif 16 : 17 : namespace elsa::detail 18 : { 19 : void assert_nomsg(const char* expr_str, bool expr, const char* file, int line); 20 : 21 : void assert_msg(const char* expr_str, bool expr, const char* file, int line, const char* msg); 22 : } // namespace elsa::detail 23 : 24 27548972 : #define GET_MACRO(_1, _2, NAME, ...) NAME 25 : 26 : #define ELSA_VERIFY_IMPL2(Expr, Msg) \ 27 : ::elsa::detail::assert_msg(#Expr, Expr, __FILE__, __LINE__, Msg) 28 27548972 : #define ELSA_VERIFY_IMPL1(Expr) ::elsa::detail::assert_nomsg(#Expr, Expr, __FILE__, __LINE__) 29 : 30 27548972 : #define ELSA_VERIFY(...) GET_MACRO(__VA_ARGS__, ELSA_VERIFY_IMPL2, ELSA_VERIFY_IMPL1)(__VA_ARGS__) 31 : 32 : #define ELSA_TODO() ELSA_VERIFY(false, "TODO")