aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/winapi
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-10-18 02:38:23 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-10-18 03:12:02 +0300
commit25f39c16c2024bd7c9e03b4bc84625d0c8eed849 (patch)
treee00ddafc6d887c6f4d8c7fa709d51d0edea965d3 /include/winapi
parentmore convenience overloads (diff)
downloadwinapi-utf8-25f39c16c2024bd7c9e03b4bc84625d0c8eed849.tar.gz
winapi-utf8-25f39c16c2024bd7c9e03b4bc84625d0c8eed849.zip
much more type-safe & generic overloads
Diffstat (limited to 'include/winapi')
-rw-r--r--include/winapi/utf8.hpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/include/winapi/utf8.hpp b/include/winapi/utf8.hpp
index c6fc77b..9469fd7 100644
--- a/include/winapi/utf8.hpp
+++ b/include/winapi/utf8.hpp
@@ -6,18 +6,26 @@
#pragma once
#include <cstddef>
+#include <memory>
#include <string>
#include <vector>
namespace winapi {
std::wstring widen(const std::string&);
-std::wstring widen(const std::vector<unsigned char>&);
std::wstring widen(const void*, std::size_t nb);
+template <typename T, typename Alloc = std::allocator<T>>
+std::wstring widen(const std::vector<T, Alloc>& src) {
+ return widen(src.data(), src.size() * sizeof(T));
+}
+
std::string narrow(const std::wstring&);
-std::string narrow(const wchar_t*, std::size_t nch);
-std::string narrow(const std::vector<unsigned char>&);
std::string narrow(const void*, std::size_t nb);
+template <typename T, typename Alloc = std::allocator<T>>
+std::string narrow(const std::vector<T, Alloc>& src) {
+ return narrow(src.data(), src.size() * sizeof(T));
+}
+
} // namespace winapi