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 <string_view> yet.
This commit is contained in:
Max Kellermann 2019-08-05 10:23:05 +02:00
parent 8b399b7133
commit 91fb91d89c

View File

@ -32,9 +32,14 @@
#include "ConstBuffer.hxx"
#include "StringAPI.hxx"
#include "Compiler.h"
#include <utility>
#if !GCC_OLDER_THAN(7,0)
#include <string_view>
#endif
template<typename T>
struct BasicStringView : ConstBuffer<T> {
typedef typename ConstBuffer<T>::size_type size_type;
@ -66,6 +71,15 @@ struct BasicStringView : ConstBuffer<T> {
constexpr BasicStringView(std::nullptr_t n) noexcept
:ConstBuffer<T>(n) {}
#if !GCC_OLDER_THAN(7,0)
constexpr BasicStringView(std::basic_string_view<T> src) noexcept
:ConstBuffer<T>(src.data(), src.size()) {}
constexpr operator std::basic_string_view<T>() const noexcept {
return {data, size};
}
#endif
using ConstBuffer<T>::empty;
using ConstBuffer<T>::begin;
using ConstBuffer<T>::end;