#pragma once #include "compat/format.hpp" #include #include #include namespace floormat { struct base_exception {}; struct exception : std::exception, base_exception { template exception(const Fmt& fmt, Ts&&... args) noexcept; exception(exception&&) noexcept; exception(const exception& other) noexcept; exception& operator=(exception&&) noexcept; exception& operator=(const exception& other) noexcept; const char* what() const noexcept override; private: fmt::memory_buffer buf; }; template exception::exception(const Fmt& fmt, Ts&&... args) noexcept { fmt::format_to(std::back_inserter(buf), fmt, forward(args)...); // todo remove buf.push_back('\0'); } } // namespace floormat #define fm_soft_assert(...) \ do { \ if (!(__VA_ARGS__)) /*NOLINT(*-simplify-boolean-expr)*/ \ { \ if (std::is_constant_evaluated()) \ throw ::floormat::base_exception{}; \ else \ throw ::floormat::exception{ \ "assertion failed: {} in {}:{}"_cf, \ #__VA_ARGS__, \ __FILE__, (floormat::size_t)__LINE__ \ }; \ } \ } while (false) #define fm_throw(fmt, ...) \ do { \ if (std::is_constant_evaluated()) \ throw ::floormat::base_exception{}; \ else \ throw ::floormat::exception{fmt, __VA_ARGS__}; \ } while (false)