export module debug.assertions; import std; namespace lt::debug { /////////////////////////////////////// // ----------* INTERFACE *--------- // ///////////////////////////////////// export template struct ensure { ensure( const Expression_T &expression, std::format_string fmt, Args_T &&...args, const std::source_location &location = std::source_location::current() ); }; export template ensure(Expression_T, std::format_string, Args_T &&...) -> ensure; /////////////////////////////////////// // * IMPLEMENTATION -- TEMPLATES * // ///////////////////////////////////// template ensure::ensure( const Expression_T &expression, std::format_string fmt, Args_T &&...args, const std::source_location &location ) { if (!static_cast(expression)) { throw std::runtime_error { std::format( "exception: {}\nlocation: {}:{}", std::format(fmt, std::forward(args)...), location.file_name(), location.line() ) }; } } } // namespace lt::debug