summaryrefslogtreecommitdiffstatshomepage
path: root/include/winapi
diff options
context:
space:
mode:
Diffstat (limited to 'include/winapi')
-rw-r--r--include/winapi/buffer.hpp9
-rw-r--r--include/winapi/error.hpp6
2 files changed, 5 insertions, 10 deletions
diff --git a/include/winapi/buffer.hpp b/include/winapi/buffer.hpp
index bebd05f..1009ebb 100644
--- a/include/winapi/buffer.hpp
+++ b/include/winapi/buffer.hpp
@@ -7,8 +7,8 @@
#include <cstddef>
#include <cstring>
+#include <format>
#include <initializer_list>
-#include <sstream>
#include <stdexcept>
#include <string>
#include <string_view>
@@ -67,11 +67,8 @@ public:
std::wstring as_utf16() const {
const auto c_str = reinterpret_cast<const wchar_t*>(data());
const auto nb = size();
- if (nb % 2 != 0) {
- std::ostringstream oss;
- oss << "Buffer size invalid at " << nb << " bytes";
- throw std::runtime_error{oss.str()};
- }
+ if (nb % 2 != 0)
+ throw std::runtime_error{std::format("Buffer size invalid at {} bytes", nb)};
const auto nch = nb / 2;
return {c_str, nch};
}
diff --git a/include/winapi/error.hpp b/include/winapi/error.hpp
index 35e10f0..30237e3 100644
--- a/include/winapi/error.hpp
+++ b/include/winapi/error.hpp
@@ -13,7 +13,7 @@
#include <windows.h>
#include <cstdint>
-#include <sstream>
+#include <format>
#include <stdexcept>
#include <string>
#include <system_error>
@@ -44,9 +44,7 @@ std::system_error windows(DWORD code, const char* function);
template <typename Ret>
std::runtime_error custom(Ret ret, const char* function) {
- std::ostringstream oss;
- oss << "Function " << function << " failed with error code " << ret;
- return std::runtime_error{oss.str()};
+ return std::runtime_error{std::format("Function {} failed with error code {}", function, ret)};
}
} // namespace error