2015-12-04 17:23:13 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// This code is licensed under the MIT License (MIT).
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
//
|
2015-08-20 21:09:14 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-11-04 15:42:27 -05:00
|
|
|
#ifndef GSL_STRING_SPAN_H
|
|
|
|
#define GSL_STRING_SPAN_H
|
2015-09-24 21:08:34 -04:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
#include <gsl/gsl_assert>
|
|
|
|
#include <gsl/gsl_util>
|
|
|
|
#include <gsl/span>
|
2017-04-20 10:51:37 -04:00
|
|
|
|
2016-08-01 16:10:02 -04:00
|
|
|
#include <cstdint>
|
2015-08-20 21:09:14 -04:00
|
|
|
#include <cstring>
|
2015-12-22 07:26:38 -05:00
|
|
|
#include <string>
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2015-11-05 12:29:30 -05:00
|
|
|
#ifdef _MSC_VER
|
2017-04-20 10:51:37 -04:00
|
|
|
#pragma warning(push)
|
|
|
|
|
|
|
|
// blanket turn off warnings from CppCoreCheck for now
|
|
|
|
// so people aren't annoyed by them when running the tool.
|
|
|
|
// more targeted suppressions will be added in a future update to the GSL
|
|
|
|
#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495)
|
|
|
|
|
|
|
|
#if _MSC_VER < 1910
|
|
|
|
#pragma push_macro("constexpr")
|
|
|
|
#define constexpr /*constexpr*/
|
|
|
|
|
|
|
|
#endif // _MSC_VER < 1910
|
|
|
|
#endif // _MSC_VER
|
2015-11-05 12:29:30 -05:00
|
|
|
|
2015-11-30 15:24:00 -05:00
|
|
|
// In order to test the library, we need it to throw exceptions that we can catch
|
|
|
|
#ifdef GSL_THROW_ON_CONTRACT_VIOLATION
|
2017-04-20 10:51:37 -04:00
|
|
|
#define GSL_NOEXCEPT /*noexcept*/
|
2017-02-07 18:59:37 -05:00
|
|
|
#else
|
2017-04-20 10:51:37 -04:00
|
|
|
#define GSL_NOEXCEPT noexcept
|
2015-11-24 02:05:31 -05:00
|
|
|
#endif // GSL_THROW_ON_CONTRACT_VIOLATION
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2015-09-29 19:41:37 -04:00
|
|
|
namespace gsl
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// czstring and wzstring
|
|
|
|
//
|
2017-02-07 18:59:37 -05:00
|
|
|
// These are "tag" typedefs for C-style strings (i.e. null-terminated character arrays)
|
2015-08-20 21:09:14 -04:00
|
|
|
// that allow static analysis to help find bugs.
|
|
|
|
//
|
|
|
|
// There are no additional features/semantics that we can find a way to add inside the
|
|
|
|
// type system for these types that will not either incur significant runtime costs or
|
|
|
|
// (sometimes needlessly) break existing programs when introduced.
|
|
|
|
//
|
2016-02-03 22:04:39 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using basic_zstring = CharT*;
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using czstring = basic_zstring<const char, Extent>;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using cwzstring = basic_zstring<const wchar_t, Extent>;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using zstring = basic_zstring<char, Extent>;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using wzstring = basic_zstring<wchar_t, Extent>;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-08-18 22:32:08 -04:00
|
|
|
namespace details
|
|
|
|
{
|
2017-04-20 10:51:37 -04:00
|
|
|
inline std::ptrdiff_t string_length(const char* str, std::ptrdiff_t n)
|
2016-08-18 22:32:08 -04:00
|
|
|
{
|
2017-04-20 10:51:37 -04:00
|
|
|
if (str == nullptr || n <= 0) return 0;
|
2016-08-18 22:32:08 -04:00
|
|
|
|
|
|
|
span<const char> str_span{str, n};
|
|
|
|
|
2016-10-17 15:41:24 -04:00
|
|
|
std::ptrdiff_t len = 0;
|
2017-04-20 10:51:37 -04:00
|
|
|
while (len < n && str_span[len]) len++;
|
2016-08-18 22:32:08 -04:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2016-09-28 12:00:47 -04:00
|
|
|
|
2017-04-20 10:51:37 -04:00
|
|
|
inline std::ptrdiff_t wstring_length(const wchar_t* str, std::ptrdiff_t n)
|
2016-09-28 12:00:47 -04:00
|
|
|
{
|
2017-04-20 10:51:37 -04:00
|
|
|
if (str == nullptr || n <= 0) return 0;
|
2016-09-28 12:00:47 -04:00
|
|
|
|
|
|
|
span<const wchar_t> str_span{str, n};
|
|
|
|
|
2016-10-17 15:41:24 -04:00
|
|
|
std::ptrdiff_t len = 0;
|
2017-04-20 10:51:37 -04:00
|
|
|
while (len < n && str_span[len]) len++;
|
2016-09-28 12:00:47 -04:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2016-08-18 22:32:08 -04:00
|
|
|
}
|
|
|
|
|
2015-08-20 21:09:14 -04:00
|
|
|
//
|
2015-11-24 02:05:31 -05:00
|
|
|
// ensure_sentinel()
|
2015-08-20 21:09:14 -04:00
|
|
|
//
|
2015-11-04 15:42:27 -05:00
|
|
|
// Provides a way to obtain an span from a contiguous sequence
|
2015-08-20 21:09:14 -04:00
|
|
|
// that ends with a (non-inclusive) sentinel value.
|
|
|
|
//
|
|
|
|
// Will fail-fast if sentinel cannot be found before max elements are examined.
|
|
|
|
//
|
2016-07-20 16:17:47 -04:00
|
|
|
template <typename T, const T Sentinel>
|
2016-06-26 10:00:56 -04:00
|
|
|
span<T, dynamic_extent> ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
|
|
|
auto cur = seq;
|
2015-11-03 15:44:09 -05:00
|
|
|
while ((cur - seq) < max && *cur != Sentinel) ++cur;
|
2015-11-20 19:03:00 -05:00
|
|
|
Ensures(*cur == Sentinel);
|
2016-07-20 16:17:47 -04:00
|
|
|
return {seq, cur - seq};
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-11-24 02:05:31 -05:00
|
|
|
// ensure_z - creates a span for a czstring or cwzstring.
|
2015-08-20 21:09:14 -04:00
|
|
|
// Will fail fast if a null-terminator cannot be found before
|
|
|
|
// the limit of size_type.
|
|
|
|
//
|
2016-07-20 16:17:47 -04:00
|
|
|
template <typename T>
|
|
|
|
inline span<T, dynamic_extent> ensure_z(T* const& sz, std::ptrdiff_t max = PTRDIFF_MAX)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2015-11-03 15:44:09 -05:00
|
|
|
return ensure_sentinel<T, 0>(sz, max);
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
// TODO (neilmac) there is probably a better template-magic way to get the const and non-const
|
|
|
|
// overloads to share an implementation
|
2016-06-26 10:00:56 -04:00
|
|
|
inline span<char, dynamic_extent> ensure_z(char* const& sz, std::ptrdiff_t max)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
auto len = details::string_length(sz, max);
|
2015-11-20 19:03:00 -05:00
|
|
|
Ensures(sz[len] == 0);
|
2016-10-17 15:41:24 -04:00
|
|
|
return {sz, len};
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
inline span<const char, dynamic_extent> ensure_z(const char* const& sz, std::ptrdiff_t max)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
auto len = details::string_length(sz, max);
|
2015-11-24 02:05:31 -05:00
|
|
|
Ensures(sz[len] == 0);
|
2016-10-17 15:41:24 -04:00
|
|
|
return {sz, len};
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
inline span<wchar_t, dynamic_extent> ensure_z(wchar_t* const& sz, std::ptrdiff_t max)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
auto len = details::wstring_length(sz, max);
|
2015-11-24 02:05:31 -05:00
|
|
|
Ensures(sz[len] == 0);
|
2016-10-17 15:41:24 -04:00
|
|
|
return {sz, len};
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
inline span<const wchar_t, dynamic_extent> ensure_z(const wchar_t* const& sz, std::ptrdiff_t max)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
auto len = details::wstring_length(sz, max);
|
2015-11-24 02:05:31 -05:00
|
|
|
Ensures(sz[len] == 0);
|
2016-10-17 15:41:24 -04:00
|
|
|
return {sz, len};
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
2017-02-13 15:11:45 -05:00
|
|
|
template <typename T, std::size_t N>
|
2016-07-20 16:17:47 -04:00
|
|
|
span<T, dynamic_extent> ensure_z(T (&sz)[N])
|
|
|
|
{
|
|
|
|
return ensure_z(&sz[0], static_cast<std::ptrdiff_t>(N));
|
|
|
|
}
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <class Cont>
|
|
|
|
span<typename std::remove_pointer<typename Cont::pointer>::type, dynamic_extent>
|
|
|
|
ensure_z(Cont& cont)
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
2015-11-11 23:48:42 -05:00
|
|
|
return ensure_z(cont.data(), static_cast<std::ptrdiff_t>(cont.length()));
|
2015-08-20 21:09:14 -04:00
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t>
|
2015-11-30 15:24:00 -05:00
|
|
|
class basic_string_span;
|
|
|
|
|
|
|
|
namespace details
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
struct is_basic_string_span_oracle : std::false_type
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
};
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2015-11-24 02:05:31 -05:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent>
|
|
|
|
struct is_basic_string_span_oracle<basic_string_span<CharT, Extent>> : std::true_type
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
};
|
2015-11-30 15:24:00 -05:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct is_basic_string_span : is_basic_string_span_oracle<std::remove_cv_t<T>>
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
};
|
2015-11-24 02:05:31 -05:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct length_func
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
};
|
2015-11-24 02:05:31 -05:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct length_func<char>
|
|
|
|
{
|
2017-03-10 12:02:13 -05:00
|
|
|
std::ptrdiff_t operator()(const char* const ptr, std::ptrdiff_t length) GSL_NOEXCEPT
|
2015-11-24 02:05:31 -05:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
return details::string_length(ptr, length);
|
2015-11-24 02:05:31 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct length_func<wchar_t>
|
|
|
|
{
|
2017-03-10 12:02:13 -05:00
|
|
|
std::ptrdiff_t operator()(const wchar_t* const ptr, std::ptrdiff_t length) GSL_NOEXCEPT
|
2015-11-24 02:05:31 -05:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
return details::wstring_length(ptr, length);
|
2015-11-24 02:05:31 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct length_func<const char>
|
|
|
|
{
|
2017-02-07 18:59:37 -05:00
|
|
|
std::ptrdiff_t operator()(const char* const ptr, std::ptrdiff_t length) GSL_NOEXCEPT
|
2015-11-24 02:05:31 -05:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
return details::string_length(ptr, length);
|
2015-11-24 02:05:31 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct length_func<const wchar_t>
|
|
|
|
{
|
2017-02-07 18:59:37 -05:00
|
|
|
std::ptrdiff_t operator()(const wchar_t* const ptr, std::ptrdiff_t length) GSL_NOEXCEPT
|
2015-11-24 02:05:31 -05:00
|
|
|
{
|
2016-10-17 15:41:24 -04:00
|
|
|
return details::wstring_length(ptr, length);
|
2015-11-24 02:05:31 -05:00
|
|
|
}
|
|
|
|
};
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// string_span and relatives
|
|
|
|
//
|
2016-06-26 10:00:56 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = dynamic_extent>
|
2015-11-30 15:24:00 -05:00
|
|
|
class basic_string_span
|
|
|
|
{
|
2015-12-04 20:03:19 -05:00
|
|
|
public:
|
2016-07-26 21:34:27 -04:00
|
|
|
using element_type = CharT;
|
|
|
|
using pointer = std::add_pointer_t<element_type>;
|
|
|
|
using reference = std::add_lvalue_reference_t<element_type>;
|
|
|
|
using const_reference = std::add_lvalue_reference_t<std::add_const_t<element_type>>;
|
|
|
|
using impl_type = span<element_type, Extent>;
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
using index_type = typename impl_type::index_type;
|
2015-11-24 02:05:31 -05:00
|
|
|
using iterator = typename impl_type::iterator;
|
|
|
|
using const_iterator = typename impl_type::const_iterator;
|
|
|
|
using reverse_iterator = typename impl_type::reverse_iterator;
|
|
|
|
using const_reverse_iterator = typename impl_type::const_reverse_iterator;
|
|
|
|
|
|
|
|
// default (empty)
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_string_span() GSL_NOEXCEPT = default;
|
2015-11-30 15:24:00 -05:00
|
|
|
|
|
|
|
// copy
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_string_span(const basic_string_span& other) GSL_NOEXCEPT = default;
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
// move
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_string_span(basic_string_span&& other) GSL_NOEXCEPT = default;
|
2015-11-24 02:05:31 -05:00
|
|
|
|
|
|
|
// assign
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_string_span& operator=(const basic_string_span& other) GSL_NOEXCEPT = default;
|
2015-11-24 02:05:31 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
// move assign
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_string_span& operator=(basic_string_span&& other) GSL_NOEXCEPT = default;
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// from nullptr
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_string_span(std::nullptr_t ptr) GSL_NOEXCEPT : span_(ptr) {}
|
2015-12-04 17:23:13 -05:00
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
constexpr basic_string_span(pointer ptr, index_type length) : span_(ptr, length) {}
|
|
|
|
constexpr basic_string_span(pointer firstElem, pointer lastElem) : span_(firstElem, lastElem) {}
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// From static arrays - if 0-terminated, remove 0 from the view
|
2016-07-26 21:34:27 -04:00
|
|
|
// All other containers allow 0s within the length, so we do not remove them
|
2017-02-13 15:11:45 -05:00
|
|
|
template <std::size_t N>
|
2016-07-26 21:34:27 -04:00
|
|
|
constexpr basic_string_span(element_type (&arr)[N]) : span_(remove_z(arr))
|
|
|
|
{
|
|
|
|
}
|
2016-07-26 22:19:47 -04:00
|
|
|
|
2017-02-13 15:11:45 -05:00
|
|
|
template <std::size_t N, class ArrayElementType = std::remove_const_t<element_type>>
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_string_span(std::array<ArrayElementType, N>& arr) GSL_NOEXCEPT : span_(arr)
|
2016-07-26 22:19:47 -04:00
|
|
|
{
|
|
|
|
}
|
2016-07-26 21:34:27 -04:00
|
|
|
|
2017-02-13 15:11:45 -05:00
|
|
|
template <std::size_t N, class ArrayElementType = std::remove_const_t<element_type>>
|
2017-04-20 10:51:37 -04:00
|
|
|
constexpr basic_string_span(const std::array<ArrayElementType, N>& arr) GSL_NOEXCEPT
|
|
|
|
: span_(arr)
|
2016-07-26 22:19:47 -04:00
|
|
|
{
|
|
|
|
}
|
2016-07-26 21:34:27 -04:00
|
|
|
|
|
|
|
// Container signature should work for basic_string after C++17 version exists
|
|
|
|
template <class Traits, class Allocator>
|
|
|
|
constexpr basic_string_span(std::basic_string<element_type, Traits, Allocator>& str)
|
2016-11-03 21:38:32 -04:00
|
|
|
: span_(&str[0], narrow_cast<std::ptrdiff_t>(str.length()))
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
}
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
template <class Traits, class Allocator>
|
|
|
|
constexpr basic_string_span(const std::basic_string<element_type, Traits, Allocator>& str)
|
2016-07-26 22:19:47 -04:00
|
|
|
: span_(&str[0], str.length())
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
}
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
// from containers. Containers must have a pointer type and data() function signatures
|
|
|
|
template <class Container,
|
|
|
|
class = std::enable_if_t<
|
|
|
|
!details::is_basic_string_span<Container>::value &&
|
|
|
|
std::is_convertible<typename Container::pointer, pointer>::value &&
|
2016-07-26 22:19:47 -04:00
|
|
|
std::is_convertible<typename Container::pointer,
|
|
|
|
decltype(std::declval<Container>().data())>::value>>
|
2016-07-26 21:34:27 -04:00
|
|
|
constexpr basic_string_span(Container& cont) : span_(cont)
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
}
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
template <class Container,
|
|
|
|
class = std::enable_if_t<
|
|
|
|
!details::is_basic_string_span<Container>::value &&
|
|
|
|
std::is_convertible<typename Container::pointer, pointer>::value &&
|
2016-07-26 22:19:47 -04:00
|
|
|
std::is_convertible<typename Container::pointer,
|
|
|
|
decltype(std::declval<Container>().data())>::value>>
|
2016-07-26 21:34:27 -04:00
|
|
|
constexpr basic_string_span(const Container& cont) : span_(cont)
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
|
|
|
}
|
2015-11-24 02:05:31 -05:00
|
|
|
|
2015-11-30 15:24:00 -05:00
|
|
|
// from string_span
|
2016-07-26 22:19:47 -04:00
|
|
|
template <
|
|
|
|
class OtherValueType, std::ptrdiff_t OtherExtent,
|
|
|
|
class = std::enable_if_t<std::is_convertible<
|
|
|
|
typename basic_string_span<OtherValueType, OtherExtent>::impl_type, impl_type>::value>>
|
|
|
|
constexpr basic_string_span(basic_string_span<OtherValueType, OtherExtent> other)
|
2015-11-24 02:05:31 -05:00
|
|
|
: span_(other.data(), other.length())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
template <index_type Count>
|
2016-07-26 22:19:47 -04:00
|
|
|
constexpr basic_string_span<element_type, Count> first() const
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
2016-07-20 16:17:47 -04:00
|
|
|
return {span_.template first<Count>()};
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
2016-07-27 16:48:29 -04:00
|
|
|
constexpr basic_string_span<element_type, dynamic_extent> first(index_type count) const
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
2016-07-20 16:17:47 -04:00
|
|
|
return {span_.first(count)};
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
template <index_type Count>
|
2016-07-27 16:48:29 -04:00
|
|
|
constexpr basic_string_span<element_type, Count> last() const
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
2016-07-20 16:17:47 -04:00
|
|
|
return {span_.template last<Count>()};
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
2016-07-26 22:19:47 -04:00
|
|
|
constexpr basic_string_span<element_type, dynamic_extent> last(index_type count) const
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
2016-07-20 16:17:47 -04:00
|
|
|
return {span_.last(count)};
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
template <index_type Offset, index_type Count>
|
2016-07-26 22:19:47 -04:00
|
|
|
constexpr basic_string_span<element_type, Count> subspan() const
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
2016-07-20 16:17:47 -04:00
|
|
|
return {span_.template subspan<Offset, Count>()};
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
constexpr basic_string_span<element_type, dynamic_extent>
|
2016-07-26 22:19:47 -04:00
|
|
|
subspan(index_type offset, index_type count = dynamic_extent) const
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
2016-07-20 16:17:47 -04:00
|
|
|
return {span_.subspan(offset, count)};
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
constexpr reference operator[](index_type idx) const { return span_[idx]; }
|
|
|
|
constexpr reference operator()(index_type idx) const { return span_[idx]; }
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
constexpr pointer data() const { return span_.data(); }
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr index_type length() const GSL_NOEXCEPT { return span_.size(); }
|
|
|
|
constexpr index_type size() const GSL_NOEXCEPT { return span_.size(); }
|
|
|
|
constexpr index_type size_bytes() const GSL_NOEXCEPT { return span_.size_bytes(); }
|
|
|
|
constexpr index_type length_bytes() const GSL_NOEXCEPT { return span_.length_bytes(); }
|
|
|
|
constexpr bool empty() const GSL_NOEXCEPT { return size() == 0; }
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr iterator begin() const GSL_NOEXCEPT { return span_.begin(); }
|
|
|
|
constexpr iterator end() const GSL_NOEXCEPT { return span_.end(); }
|
2016-07-26 22:19:47 -04:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr const_iterator cbegin() const GSL_NOEXCEPT { return span_.cbegin(); }
|
|
|
|
constexpr const_iterator cend() const GSL_NOEXCEPT { return span_.cend(); }
|
2016-07-26 22:19:47 -04:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr reverse_iterator rbegin() const GSL_NOEXCEPT { return span_.rbegin(); }
|
|
|
|
constexpr reverse_iterator rend() const GSL_NOEXCEPT { return span_.rend(); }
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr const_reverse_iterator crbegin() const GSL_NOEXCEPT { return span_.crbegin(); }
|
|
|
|
constexpr const_reverse_iterator crend() const GSL_NOEXCEPT { return span_.crend(); }
|
2015-11-30 15:24:00 -05:00
|
|
|
|
|
|
|
private:
|
2016-07-26 22:19:47 -04:00
|
|
|
static impl_type remove_z(pointer const& sz, std::ptrdiff_t max)
|
2015-11-24 02:05:31 -05:00
|
|
|
{
|
2016-07-26 21:34:27 -04:00
|
|
|
return {sz, details::length_func<element_type>()(sz, max)};
|
2015-11-24 02:05:31 -05:00
|
|
|
}
|
|
|
|
|
2017-02-13 15:11:45 -05:00
|
|
|
template <std::size_t N>
|
2016-07-26 22:19:47 -04:00
|
|
|
static impl_type remove_z(element_type (&sz)[N])
|
2015-11-24 02:05:31 -05:00
|
|
|
{
|
|
|
|
return remove_z(&sz[0], narrow_cast<std::ptrdiff_t>(N));
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_type span_;
|
2015-11-30 15:24:00 -05:00
|
|
|
};
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2015-11-30 15:24:00 -05:00
|
|
|
using string_span = basic_string_span<char, Extent>;
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2015-11-30 15:24:00 -05:00
|
|
|
using cstring_span = basic_string_span<const char, Extent>;
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2015-11-30 15:24:00 -05:00
|
|
|
using wstring_span = basic_string_span<wchar_t, Extent>;
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <std::ptrdiff_t Extent = dynamic_extent>
|
2015-11-30 15:24:00 -05:00
|
|
|
using cwstring_span = basic_string_span<const wchar_t, Extent>;
|
|
|
|
|
2015-08-20 21:09:14 -04:00
|
|
|
//
|
2015-11-04 15:42:27 -05:00
|
|
|
// to_string() allow (explicit) conversions from string_span to string
|
2015-08-20 21:09:14 -04:00
|
|
|
//
|
2015-11-05 12:29:30 -05:00
|
|
|
|
2016-07-26 21:34:27 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent>
|
2016-07-20 16:17:47 -04:00
|
|
|
std::basic_string<typename std::remove_const<CharT>::type>
|
|
|
|
to_string(basic_string_span<CharT, Extent> view)
|
2015-11-05 12:29:30 -05:00
|
|
|
{
|
2017-02-13 15:11:45 -05:00
|
|
|
return {view.data(), static_cast<std::size_t>(view.length())};
|
2015-11-05 12:29:30 -05:00
|
|
|
}
|
|
|
|
|
2017-04-20 10:51:37 -04:00
|
|
|
template <typename CharT, typename Traits = typename std::char_traits<CharT>,
|
|
|
|
typename Allocator = std::allocator<CharT>, typename gCharT, std::ptrdiff_t Extent>
|
2016-09-04 02:29:10 -04:00
|
|
|
std::basic_string<CharT, Traits, Allocator> to_basic_string(basic_string_span<gCharT, Extent> view)
|
|
|
|
{
|
2017-04-20 10:51:37 -04:00
|
|
|
return {view.data(), static_cast<std::size_t>(view.length())};
|
2016-09-04 02:29:10 -04:00
|
|
|
}
|
2017-02-07 18:59:37 -05:00
|
|
|
|
2016-02-03 22:04:39 -05:00
|
|
|
// zero-terminated string span, used to convert
|
|
|
|
// zero-terminated spans to legacy strings
|
2016-07-20 16:17:47 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
class basic_zstring_span
|
2015-08-20 21:09:14 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
using value_type = CharT;
|
2016-02-03 22:04:39 -05:00
|
|
|
using const_value_type = std::add_const_t<CharT>;
|
|
|
|
|
|
|
|
using pointer = std::add_pointer_t<value_type>;
|
|
|
|
using const_pointer = std::add_pointer_t<const_value_type>;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-02-03 22:04:39 -05:00
|
|
|
using zstring_type = basic_zstring<value_type, Extent>;
|
|
|
|
using const_zstring_type = basic_zstring<const_value_type, Extent>;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
using impl_type = span<value_type, Extent>;
|
2016-02-03 22:04:39 -05:00
|
|
|
using string_span_type = basic_string_span<value_type, Extent>;
|
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr basic_zstring_span(impl_type s) GSL_NOEXCEPT : span_(s)
|
2016-02-03 22:04:39 -05:00
|
|
|
{
|
|
|
|
// expects a zero-terminated span
|
2016-06-26 10:00:56 -04:00
|
|
|
Expects(s[s.size() - 1] == '\0');
|
2016-02-03 22:04:39 -05:00
|
|
|
}
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-02-06 13:46:40 -05:00
|
|
|
// copy
|
|
|
|
constexpr basic_zstring_span(const basic_zstring_span& other) = default;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
// move
|
2016-02-06 13:46:40 -05:00
|
|
|
constexpr basic_zstring_span(basic_zstring_span&& other) = default;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-02-06 13:46:40 -05:00
|
|
|
// assign
|
|
|
|
constexpr basic_zstring_span& operator=(const basic_zstring_span& other) = default;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
// move assign
|
2016-02-06 13:46:40 -05:00
|
|
|
constexpr basic_zstring_span& operator=(basic_zstring_span&& other) = default;
|
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr bool empty() const GSL_NOEXCEPT { return span_.size() == 0; }
|
2016-02-06 13:46:40 -05:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr string_span_type as_string_span() const GSL_NOEXCEPT
|
2016-07-20 16:17:47 -04:00
|
|
|
{
|
2016-10-28 02:45:54 -04:00
|
|
|
auto sz = span_.size();
|
|
|
|
return span_.first(sz <= 0 ? 0 : sz - 1);
|
2016-07-20 16:17:47 -04:00
|
|
|
}
|
2016-02-06 13:46:40 -05:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr string_span_type ensure_z() const GSL_NOEXCEPT { return gsl::ensure_z(span_); }
|
2016-02-06 13:46:40 -05:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
constexpr const_zstring_type assume_z() const GSL_NOEXCEPT { return span_.data(); }
|
2015-08-20 21:09:14 -04:00
|
|
|
|
|
|
|
private:
|
2016-02-06 13:46:40 -05:00
|
|
|
impl_type span_;
|
2015-08-20 21:09:14 -04:00
|
|
|
};
|
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
template <std::ptrdiff_t Max = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using zstring_span = basic_zstring_span<char, Max>;
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
template <std::ptrdiff_t Max = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using wzstring_span = basic_zstring_span<wchar_t, Max>;
|
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
template <std::ptrdiff_t Max = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using czstring_span = basic_zstring_span<const char, Max>;
|
|
|
|
|
2016-06-26 10:00:56 -04:00
|
|
|
template <std::ptrdiff_t Max = dynamic_extent>
|
2016-02-03 22:04:39 -05:00
|
|
|
using cwzstring_span = basic_zstring_span<const wchar_t, Max>;
|
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// operator ==
|
2016-07-26 21:34:27 -04:00
|
|
|
template <class CharT, std::ptrdiff_t Extent, class T,
|
2016-07-26 22:19:47 -04:00
|
|
|
class = std::enable_if_t<
|
|
|
|
details::is_basic_string_span<T>::value ||
|
|
|
|
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>>>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator==(const gsl::basic_string_span<CharT, Extent>& one, const T& other) GSL_NOEXCEPT
|
2015-12-04 17:23:13 -05:00
|
|
|
{
|
2017-04-02 15:30:49 -04:00
|
|
|
const gsl::basic_string_span<std::add_const_t<CharT>> tmp(other);
|
2015-12-04 17:23:13 -05:00
|
|
|
return std::equal(one.begin(), one.end(), tmp.begin(), tmp.end());
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:19:47 -04:00
|
|
|
template <class CharT, std::ptrdiff_t Extent, class T,
|
|
|
|
class = std::enable_if_t<
|
|
|
|
!details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>>>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator==(const T& one, const gsl::basic_string_span<CharT, Extent>& other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
2016-07-26 21:34:27 -04:00
|
|
|
gsl::basic_string_span<std::add_const_t<CharT>> tmp(one);
|
2015-12-04 20:03:19 -05:00
|
|
|
return std::equal(tmp.begin(), tmp.end(), other.begin(), other.end());
|
|
|
|
}
|
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// operator !=
|
2016-06-26 10:00:56 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2016-07-20 16:17:47 -04:00
|
|
|
typename = std::enable_if_t<std::is_convertible<
|
|
|
|
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator!=(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 17:23:13 -05:00
|
|
|
{
|
|
|
|
return !(one == other);
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 17:23:13 -05:00
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
|
|
|
!gsl::details::is_basic_string_span<T>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator!=(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
return !(one == other);
|
|
|
|
}
|
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// operator<
|
2016-06-26 10:00:56 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2016-07-20 16:17:47 -04:00
|
|
|
typename = std::enable_if_t<std::is_convertible<
|
|
|
|
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
2017-04-02 15:30:49 -04:00
|
|
|
const gsl::basic_string_span<std::add_const_t<CharT>, Extent> tmp(other);
|
2015-12-04 20:03:19 -05:00
|
|
|
return std::lexicographical_compare(one.begin(), one.end(), tmp.begin(), tmp.end());
|
2015-11-30 15:24:00 -05:00
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 17:23:13 -05:00
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
|
|
|
!gsl::details::is_basic_string_span<T>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-12-04 17:23:13 -05:00
|
|
|
{
|
|
|
|
gsl::basic_string_span<std::add_const_t<CharT>, Extent> tmp(one);
|
|
|
|
return std::lexicographical_compare(tmp.begin(), tmp.end(), other.begin(), other.end());
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
#ifndef _MSC_VER
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2015-12-07 18:30:00 -05:00
|
|
|
// VS treats temp and const containers as convertible to basic_string_span,
|
|
|
|
// so the cases below are already covered by the previous operators
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
gsl::basic_string_span<std::add_const_t<CharT>, Extent> tmp(other);
|
|
|
|
return std::lexicographical_compare(one.begin(), one.end(), tmp.begin(), tmp.end());
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
gsl::basic_string_span<std::add_const_t<CharT>, Extent> tmp(one);
|
|
|
|
return std::lexicographical_compare(tmp.begin(), tmp.end(), other.begin(), other.end());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// operator <=
|
2016-06-26 10:00:56 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2016-07-20 16:17:47 -04:00
|
|
|
typename = std::enable_if_t<std::is_convertible<
|
|
|
|
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 17:23:13 -05:00
|
|
|
{
|
|
|
|
return !(other < one);
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 17:23:13 -05:00
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
|
|
|
!gsl::details::is_basic_string_span<T>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<=(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
return !(other < one);
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
#ifndef _MSC_VER
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2015-12-07 18:30:00 -05:00
|
|
|
// VS treats temp and const containers as convertible to basic_string_span,
|
|
|
|
// so the cases below are already covered by the previous operators
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
return !(other < one);
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator<=(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
|
|
|
return !(other < one);
|
|
|
|
}
|
2015-12-04 20:03:19 -05:00
|
|
|
#endif
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// operator>
|
2016-06-26 10:00:56 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2016-07-20 16:17:47 -04:00
|
|
|
typename = std::enable_if_t<std::is_convertible<
|
|
|
|
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 17:23:13 -05:00
|
|
|
{
|
|
|
|
return other < one;
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 17:23:13 -05:00
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
|
|
|
!gsl::details::is_basic_string_span<T>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
|
|
|
return other < one;
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
#ifndef _MSC_VER
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2015-12-07 18:30:00 -05:00
|
|
|
// VS treats temp and const containers as convertible to basic_string_span,
|
|
|
|
// so the cases below are already covered by the previous operators
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
return other < one;
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
return other < one;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-04 17:23:13 -05:00
|
|
|
// operator >=
|
2016-06-26 10:00:56 -04:00
|
|
|
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2016-07-20 16:17:47 -04:00
|
|
|
typename = std::enable_if_t<std::is_convertible<
|
|
|
|
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 17:23:13 -05:00
|
|
|
{
|
|
|
|
return !(one < other);
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 17:23:13 -05:00
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
|
|
|
!gsl::details::is_basic_string_span<T>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>=(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-11-30 15:24:00 -05:00
|
|
|
{
|
|
|
|
return !(one < other);
|
|
|
|
}
|
2015-11-24 02:05:31 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
#ifndef _MSC_VER
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2015-12-07 18:30:00 -05:00
|
|
|
// VS treats temp and const containers as convertible to basic_string_span,
|
|
|
|
// so the cases below are already covered by the previous operators
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
return !(one < other);
|
|
|
|
}
|
|
|
|
|
2016-07-20 16:17:47 -04:00
|
|
|
template <
|
|
|
|
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
2015-12-04 20:03:19 -05:00
|
|
|
typename DataType = typename T::value_type,
|
|
|
|
typename Dummy = std::enable_if_t<
|
2016-07-20 16:17:47 -04:00
|
|
|
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
|
|
|
std::is_convertible<DataType*, CharT*>::value &&
|
|
|
|
std::is_same<std::decay_t<decltype(std::declval<T>().size(), *std::declval<T>().data())>,
|
|
|
|
DataType>::value>>
|
2017-02-07 18:59:37 -05:00
|
|
|
bool operator>=(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_NOEXCEPT
|
2015-12-04 20:03:19 -05:00
|
|
|
{
|
|
|
|
return !(one < other);
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-26 21:34:27 -04:00
|
|
|
} // namespace GSL
|
2015-12-04 20:03:19 -05:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
#undef GSL_NOEXCEPT
|
2015-11-30 15:24:00 -05:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2017-04-20 10:51:37 -04:00
|
|
|
#pragma warning(pop)
|
|
|
|
|
|
|
|
#if _MSC_VER < 1910
|
|
|
|
#undef constexpr
|
|
|
|
#pragma pop_macro("constexpr")
|
|
|
|
|
|
|
|
#endif // _MSC_VER < 1910
|
2017-02-07 18:59:37 -05:00
|
|
|
#endif // _MSC_VER
|
2015-11-30 15:24:00 -05:00
|
|
|
|
2015-11-04 15:42:27 -05:00
|
|
|
#endif // GSL_STRING_SPAN_H
|