Commit 91fb91d8 authored by Max Kellermann's avatar Max Kellermann

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.
parent 8b399b71
...@@ -32,9 +32,14 @@ ...@@ -32,9 +32,14 @@
#include "ConstBuffer.hxx" #include "ConstBuffer.hxx"
#include "StringAPI.hxx" #include "StringAPI.hxx"
#include "Compiler.h"
#include <utility> #include <utility>
#if !GCC_OLDER_THAN(7,0)
#include <string_view>
#endif
template<typename T> template<typename T>
struct BasicStringView : ConstBuffer<T> { struct BasicStringView : ConstBuffer<T> {
typedef typename ConstBuffer<T>::size_type size_type; typedef typename ConstBuffer<T>::size_type size_type;
...@@ -66,6 +71,15 @@ struct BasicStringView : ConstBuffer<T> { ...@@ -66,6 +71,15 @@ struct BasicStringView : ConstBuffer<T> {
constexpr BasicStringView(std::nullptr_t n) noexcept constexpr BasicStringView(std::nullptr_t n) noexcept
:ConstBuffer<T>(n) {} :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>::empty;
using ConstBuffer<T>::begin; using ConstBuffer<T>::begin;
using ConstBuffer<T>::end; using ConstBuffer<T>::end;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment