diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-04 22:39:44 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-04 22:42:12 +0200 |
| commit | 7fcbd6e474235957f2785c3d9b5344b2acf3ff77 (patch) | |
| tree | 4c1a2d5971a9db5330963ac7d77501638efeb4c0 /include/winapi/buffer.hpp | |
| parent | upgrade to `using` instead of typedef (diff) | |
| download | winapi-common-7fcbd6e474235957f2785c3d9b5344b2acf3ff77.tar.gz winapi-common-7fcbd6e474235957f2785c3d9b5344b2acf3ff77.zip | |
upgrade to std::string_view
Diffstat (limited to '')
| -rw-r--r-- | include/winapi/buffer.hpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/include/winapi/buffer.hpp b/include/winapi/buffer.hpp index a9243cb..bebd05f 100644 --- a/include/winapi/buffer.hpp +++ b/include/winapi/buffer.hpp @@ -11,6 +11,7 @@ #include <sstream> #include <stdexcept> #include <string> +#include <string_view> #include <utility> #include <vector> @@ -33,19 +34,19 @@ public: /** Construct a buffer from an instance of `std::vector<unsigned char>`. */ explicit Buffer(Parent&& src) : Parent{std::move(src)} {} - /** Construct a buffer from an instance of `std::basic_string`. */ + /** Construct a buffer from a string view. */ template <typename CharT> - explicit Buffer(const std::basic_string<CharT>& src) { + explicit Buffer(std::basic_string_view<CharT> src) { set(src); } /** Construct a buffer from a memory region. */ Buffer(const void* src, std::size_t nb) { set(src, nb); } - /** Replace the buffer's contents with the data from `std::basic_string`. */ + /** Replace the buffer's contents with the data from a string view. */ template <typename CharT> - void set(const std::basic_string<CharT>& src) { - set(src.c_str(), src.length() * sizeof(std::basic_string<CharT>::char_type)); + void set(std::basic_string_view<CharT> src) { + set(src.data(), src.length() * sizeof(std::basic_string_view<CharT>::char_type)); } /** Replace the buffer's contents with the data from a memory region. */ |
