From 59f795bd6d64e905649899f5ce542081241fec72 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 16 Mar 2019 00:15:45 -0400 Subject: [PATCH] stream: Change std::string overload for Write to use a std::string_view Allows various string types to be used with the overload without constructing a std::string (such as const char* etc). --- src/stream.cpp | 4 ++-- src/stream.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stream.cpp b/src/stream.cpp index bf0eaf3..d171830 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -12,9 +12,9 @@ Stream::Stream(std::vector& bytes) : bytes(bytes) {} Stream::~Stream() = default; -void Stream::Write(std::string string) { +void Stream::Write(std::string_view string) { const auto size{string.size()}; - const auto data{reinterpret_cast(string.data())}; + const auto data{reinterpret_cast(string.data())}; for (std::size_t i = 0; i < size; i++) { Write(data[i]); } diff --git a/src/stream.h b/src/stream.h index 20aa064..a61e4f2 100644 --- a/src/stream.h +++ b/src/stream.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include "common_types.h" @@ -17,7 +17,7 @@ public: explicit Stream(std::vector& bytes); ~Stream(); - void Write(std::string string); + void Write(std::string_view string); void Write(u64 value);