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).
This commit is contained in:
Lioncash 2019-03-16 00:15:45 -04:00 committed by ReinUsesLisp
parent 326c69896b
commit 59f795bd6d
2 changed files with 4 additions and 4 deletions

View File

@ -12,9 +12,9 @@ Stream::Stream(std::vector<u8>& 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<u8*>(string.data())};
const auto data{reinterpret_cast<const u8*>(string.data())};
for (std::size_t i = 0; i < size; i++) {
Write(data[i]);
}

View File

@ -6,7 +6,7 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
#include "common_types.h"
@ -17,7 +17,7 @@ public:
explicit Stream(std::vector<u8>& bytes);
~Stream();
void Write(std::string string);
void Write(std::string_view string);
void Write(u64 value);