#pragma once #include #include #include #include "Platform.h" #include "types.h" namespace fmt { std::string unsafe_format(const char* fmt...) noexcept; std::string unsafe_vformat(const char*, va_list) noexcept; // Formatting function template inline std::string format(const char* fmt, const Args&... args) { return unsafe_format(fmt, ::unveil::get(args)...); } // Helper class class exception_base : public std::runtime_error { // Helper (there is no other room) va_list m_args; protected: // Internal formatting constructor exception_base(const char* fmt...); }; // Exception type derived from std::runtime_error with formatting constructor class exception : public exception_base { public: template exception(const char* fmt, const Args&... args) : exception_base(fmt, ::unveil::get(args)...) { } }; // Narrow cast (similar to gsl::narrow) with exception message formatting template inline auto narrow(const char* format_str, const From& value, const Args&... args) -> decltype(static_cast(static_cast(std::declval()))) { const auto result = static_cast(value); if (static_cast(result) != value) throw fmt::exception(format_str, value, args...); return result; } }