From 91fb91d89cca1210723bafea30aa476763feb841 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 5 Aug 2019 10:23:05 +0200 Subject: [PATCH] util/StringView: prepare the transition to std::string_view Unfortunately, we need to disable this for GCC versions older than 7, because it doesn't have yet. --- src/util/StringView.hxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/StringView.hxx b/src/util/StringView.hxx index 7fc496836..d89fbd32d 100644 --- a/src/util/StringView.hxx +++ b/src/util/StringView.hxx @@ -32,9 +32,14 @@ #include "ConstBuffer.hxx" #include "StringAPI.hxx" +#include "Compiler.h" #include +#if !GCC_OLDER_THAN(7,0) +#include +#endif + template struct BasicStringView : ConstBuffer { typedef typename ConstBuffer::size_type size_type; @@ -66,6 +71,15 @@ struct BasicStringView : ConstBuffer { constexpr BasicStringView(std::nullptr_t n) noexcept :ConstBuffer(n) {} +#if !GCC_OLDER_THAN(7,0) + constexpr BasicStringView(std::basic_string_view src) noexcept + :ConstBuffer(src.data(), src.size()) {} + + constexpr operator std::basic_string_view() const noexcept { + return {data, size}; + } +#endif + using ConstBuffer::empty; using ConstBuffer::begin; using ConstBuffer::end;