add string_ref user-defined literals

This commit is contained in:
bolero-MURAKAMI 2016-03-25 10:48:59 +09:00
parent 2fce5bd7f9
commit 5bdb045730
7 changed files with 398 additions and 199 deletions

View file

@ -77,6 +77,23 @@ namespace sprout {
)...
);
}
template<typename T, std::size_t N, typename Traits, sprout::index_t... Indexes>
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
string_rshift(
sprout::basic_string<T, N, Traits> const& lhs, std::size_t lsize,
std::initializer_list<T> rhs, std::size_t rsize,
sprout::index_tuple<Indexes...>
)
{
typedef sprout::detail::string_construct_access<T, N, Traits> access_type;
return access_type::raw_construct(
sprout::detail::checked_length<N>(lsize + rsize),
(Indexes < lsize ? lhs[Indexes]
: Indexes < lsize + rsize ? rhs.begin()[Indexes - lsize]
: T()
)...
);
}
} // namespace detail
//
// operator<<
@ -108,6 +125,15 @@ namespace sprout {
sprout::make_index_tuple<N1>::make()
);
}
template<typename T, std::size_t N, typename Traits>
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
operator<<(sprout::basic_string<T, N, Traits> const& lhs, std::initializer_list<T> rhs) {
return sprout::detail::string_rshift(
lhs, lhs.size(),
rhs, rhs.size(),
sprout::make_index_tuple<N>::make()
);
}
namespace detail {
template<typename T, std::size_t N, typename Traits, sprout::index_t... Indexes>
@ -161,6 +187,23 @@ namespace sprout {
)...
);
}
template<typename T, std::size_t N, typename Traits, sprout::index_t... Indexes>
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
string_lshift(
sprout::basic_string<T, N, Traits> const& lhs, std::size_t lsize,
std::initializer_list<T> rhs, std::size_t rsize,
sprout::index_tuple<Indexes...>
)
{
typedef sprout::detail::string_construct_access<T, N, Traits> access_type;
return access_type::raw_construct(
sprout::detail::checked_length<N>(rsize + lsize),
(Indexes < rsize ? rhs.begin()[Indexes]
: Indexes < rsize + lsize ? lhs[Indexes - rsize]
: T()
)...
);
}
} // namespace detail
//
// operator>>
@ -192,6 +235,15 @@ namespace sprout {
sprout::make_index_tuple<N1>::make()
);
}
template<typename T, std::size_t N, typename Traits>
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
operator>>(sprout::basic_string<T, N, Traits> const& lhs, std::initializer_list<T> rhs) {
return sprout::detail::string_lshift(
lhs, lhs.size(),
rhs, rhs.size(),
sprout::make_index_tuple<N>::make()
);
}
} // namespace sprout
#endif // #ifndef SPROUT_STRING_SHIFT_CONCAT_HPP

View file

@ -281,28 +281,31 @@ namespace sprout {
sprout::detail::string_raw_construct_t(), n, SPROUT_FORWARD(Args, args)...
)
{}
SPROUT_CXX14_CONSTEXPR void maxcheck(size_type n) const {
if (n > static_size) {
SPROUT_CXX14_CONSTEXPR void
maxcheck(size_type n) const {
if (n > max_size()) {
throw std::out_of_range("basic_string<>: index out of range");
}
}
SPROUT_CXX14_CONSTEXPR void lengthcheck(size_type n) const {
if (n > static_size) {
SPROUT_CXX14_CONSTEXPR void
lengthcheck(size_type n) const {
if (n > max_size()) {
throw std::length_error("basic_string<>: length exceeded");
}
}
SPROUT_CXX14_CONSTEXPR void put_terminator() {
traits_type::assign(begin() + size(), static_size - size(), value_type());
SPROUT_CXX14_CONSTEXPR void
put_terminator(size_type n) {
if (n < size()) {
traits_type::assign(begin() + n, size() - n, value_type());
}
SPROUT_CXX14_CONSTEXPR void put_terminator(size_type n) {
impl_.len = n;
put_terminator();
}
template<typename InputIterator>
SPROUT_CXX14_CONSTEXPR basic_string& assign(InputIterator first, InputIterator last, std::input_iterator_tag*) {
SPROUT_CXX14_CONSTEXPR basic_string&
assign(InputIterator first, InputIterator last, std::input_iterator_tag*) {
iterator it = begin();
for (; first != last; ++first, ++it) {
if (sprout::distance(begin(), it) > static_size) {
if (sprout::distance(begin(), it) > max_size()) {
throw std::length_error("basic_string<>: length exceeded");
}
traits_type::assign(*it, *first);
@ -311,7 +314,8 @@ namespace sprout {
return *this;
}
template<typename ForwardIterator>
SPROUT_CXX14_CONSTEXPR basic_string& assign(ForwardIterator first, ForwardIterator last, std::forward_iterator_tag*) {
SPROUT_CXX14_CONSTEXPR basic_string&
assign(ForwardIterator first, ForwardIterator last, std::forward_iterator_tag*) {
lengthcheck(sprout::distance(first, last));
iterator it = begin();
for (; first != last; ++first, ++it) {
@ -321,10 +325,11 @@ namespace sprout {
return *this;
}
template<typename InputIterator>
SPROUT_CXX14_CONSTEXPR basic_string& append(InputIterator first, InputIterator last, std::input_iterator_tag*) {
SPROUT_CXX14_CONSTEXPR basic_string&
append(InputIterator first, InputIterator last, std::input_iterator_tag*) {
iterator it = end();
for (; first != last; ++first, ++it) {
if (sprout::distance(begin(), it) > static_size) {
if (sprout::distance(begin(), it) > max_size()) {
throw std::length_error("basic_string<>: length exceeded");
}
traits_type::assign(*it, *first);
@ -333,7 +338,8 @@ namespace sprout {
return *this;
}
template<typename ForwardIterator>
SPROUT_CXX14_CONSTEXPR basic_string& append(ForwardIterator first, ForwardIterator last, std::forward_iterator_tag*) {
SPROUT_CXX14_CONSTEXPR basic_string&
append(ForwardIterator first, ForwardIterator last, std::forward_iterator_tag*) {
lengthcheck(size() + sprout::distance(first, last));
iterator it = end();
for (; first != last; ++first, ++it) {
@ -437,6 +443,10 @@ namespace sprout {
operator=(value_type rhs) {
return assign(1, rhs);
}
SPROUT_CXX14_CONSTEXPR basic_string&
operator=(std::initializer_list<value_type> il) {
return assign(il);
}
// iterators:
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
SPROUT_CXX14_CONSTEXPR iterator
@ -541,6 +551,10 @@ namespace sprout {
resize(size_type n) {
resize(n, value_type());
}
SPROUT_CONSTEXPR size_type
capacity() const SPROUT_NOEXCEPT {
return static_size;
}
SPROUT_CXX14_CONSTEXPR void
clear() SPROUT_NOEXCEPT {
put_terminator(0);
@ -1063,63 +1077,80 @@ namespace sprout {
#endif
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
SPROUT_CXX14_CONSTEXPR iterator nth(size_type i) {
SPROUT_CXX14_CONSTEXPR iterator
nth(size_type i) {
return i < size()
? iterator(*this, i)
: (throw std::out_of_range("basic_string<>: index out of range"), iterator())
;
}
SPROUT_CONSTEXPR const_iterator nth(size_type i) const {
SPROUT_CONSTEXPR const_iterator
nth(size_type i) const {
return i < size()
? const_iterator(*this, i)
: (throw std::out_of_range("basic_string<>: index out of range"), const_iterator())
;
}
SPROUT_CXX14_CONSTEXPR size_type index_of(iterator p) SPROUT_NOEXCEPT {
SPROUT_CXX14_CONSTEXPR size_type
index_of(iterator p) SPROUT_NOEXCEPT {
return p.index();
}
SPROUT_CONSTEXPR size_type index_of(const_iterator p) const SPROUT_NOEXCEPT {
SPROUT_CONSTEXPR size_type
index_of(const_iterator p) const SPROUT_NOEXCEPT {
return p.index();
}
#else
SPROUT_CXX14_CONSTEXPR iterator nth(size_type i) {
SPROUT_CXX14_CONSTEXPR iterator
nth(size_type i) {
return i < size()
? data() + i
: (throw std::out_of_range("basic_string<>: index out of range"), iterator())
;
}
SPROUT_CONSTEXPR const_iterator nth(size_type i) const {
SPROUT_CONSTEXPR const_iterator
th(size_type i) const {
return i < size()
? data() + i
: (throw std::out_of_range("basic_string<>: index out of range"), const_iterator())
;
}SPROUT_CXX14_CONSTEXPR
SPROUT_CONSTEXPR size_type index_of(iterator p) SPROUT_NOEXCEPT {
SPROUT_CONSTEXPR size_type
index_of(iterator p) SPROUT_NOEXCEPT {
return sprout::distance(begin(), p);
}
SPROUT_CONSTEXPR size_type index_of(const_iterator p) const SPROUT_NOEXCEPT {
SPROUT_CONSTEXPR size_type
index_of(const_iterator p) const SPROUT_NOEXCEPT {
return sprout::distance(begin(), p);
}
#endif
SPROUT_CXX14_CONSTEXPR basic_string& operator<<=(T const& rhs) {
SPROUT_CXX14_CONSTEXPR basic_string&
operator<<=(T const& rhs) {
push_back(rhs);
return *this;
}
SPROUT_CXX14_CONSTEXPR basic_string& operator<<=(value_type const* rhs) {
SPROUT_CXX14_CONSTEXPR basic_string&
operator<<=(value_type const* rhs) {
return append(rhs);
}
template<std::size_t N2>
SPROUT_CXX14_CONSTEXPR basic_string& operator<<=(basic_string<T, N2, Traits> const& rhs) {
SPROUT_CXX14_CONSTEXPR basic_string&
operator<<=(basic_string<T, N2, Traits> const& rhs) {
return append(rhs);
}
SPROUT_CXX14_CONSTEXPR basic_string& operator>>=(T const& rhs) {
SPROUT_CXX14_CONSTEXPR basic_string&
operator<<=(std::initializer_list<value_type> rhs) {
return append(rhs);
}
SPROUT_CXX14_CONSTEXPR basic_string&
operator>>=(T const& rhs) {
lengthcheck(size() + 1);
traits_type::move(begin() + 1, begin(), size());
traits_type::assign(begin(), 1, rhs);
put_terminator(size() + 1);
return *this;
}
SPROUT_CXX14_CONSTEXPR basic_string& operator>>=(value_type const* rhs) {
SPROUT_CXX14_CONSTEXPR basic_string&
operator>>=(value_type const* rhs) {
size_type rlen = traits_type::length(rhs);
lengthcheck(size() + rlen);
traits_type::move(begin() + rlen, begin(), size());
@ -1128,7 +1159,16 @@ namespace sprout {
return *this;
}
template<std::size_t N2>
SPROUT_CXX14_CONSTEXPR basic_string& operator>>=(basic_string<T, N2, Traits> const& rhs) {
SPROUT_CXX14_CONSTEXPR basic_string&
operator>>=(basic_string<T, N2, Traits> const& rhs) {
lengthcheck(size() + rhs.size());
traits_type::move(begin() + rhs.size(), begin(), size());
traits_type::move(begin(), rhs.begin(), rhs.size());
put_terminator(size() + rhs.size());
return *this;
}
SPROUT_CXX14_CONSTEXPR basic_string&
operator>>=(std::initializer_list<value_type> rhs) {
lengthcheck(size() + rhs.size());
traits_type::move(begin() + rhs.size(), begin(), size());
traits_type::move(begin(), rhs.begin(), rhs.size());

View file

@ -16,5 +16,7 @@
#include <sprout/utility/string_ref/conversion.hpp>
#include <sprout/utility/string_ref/type_traits.hpp>
#include <sprout/utility/string_ref/alias.hpp>
#include <sprout/utility/string_ref/udl.hpp>
#include <sprout/utility/string_ref/string_view.hpp>
#endif // #ifndef SPROUT_UTILITY_STRING_REF_HPP

View file

@ -9,9 +9,7 @@
#define SPROUT_UTILITY_STRING_REF_ALIAS_HPP
#include <sprout/config.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/utility/string_ref/string_ref.hpp>
#include <sprout/utility/string_ref/type_traits.hpp>
namespace sprout {
//
@ -26,150 +24,6 @@ namespace sprout {
typedef sprout::basic_string_ref<char16_t> u16string_ref;
typedef sprout::basic_string_ref<char32_t> u32string_ref;
#endif
//
// string_view
// wstring_view
// u16string_view
// u32string_view
//
typedef sprout::basic_string_ref<char> string_view;
typedef sprout::basic_string_ref<wchar_t> wstring_view;
#if SPROUT_USE_UNICODE_LITERALS
typedef sprout::basic_string_ref<char16_t> u16string_view;
typedef sprout::basic_string_ref<char32_t> u32string_view;
#endif
#if SPROUT_USE_TEMPLATE_ALIASES
//
// basic_string_view
//
template<typename T, typename Traits = sprout::char_traits<T> >
using basic_string_view = sprout::basic_string_ref<T, Traits>;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// to_string_view
//
template<typename T, typename Traits>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T, Traits>
to_string_view(sprout::basic_string_ref<T, Traits> const& s) {
return sprout::to_string_ref(s);
}
template<typename T, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T, Traits>
to_string_view(sprout::basic_string<T, N, Traits> const& s) {
return sprout::to_string_ref(s);
}
template<typename T, typename Traits>
inline SPROUT_NON_CONSTEXPR sprout::basic_string_ref<T, Traits>
to_string_view(std::basic_string<T, Traits> const& s) {
return sprout::to_string_ref(s);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T>
to_string_view(T const* str) {
return sprout::to_string_ref(str);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T>
to_string_view(T const* str, std::size_t len) {
return sprout::to_string_ref(str, len);
}
//
// is_basic_string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_basic_string_view = sprout::is_basic_string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
struct is_basic_string_view
: public sprout::is_basic_string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_string_view_of
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
using is_string_view_of = sprout::is_string_ref_of<T, Elem>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_string_view_of
: public sprout::is_string_ref_of<T, Elem>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_string_view = sprout::is_string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_string_view
: public sprout::is_string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_wstring_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_wstring_view = sprout::is_wstring_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_wstring_view
: public sprout::is_wstring_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_UNICODE_LITERALS
//
// is_u16string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_u16string_view = sprout::is_u16string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_u16string_view
: public sprout::is_u16string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_u32string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_u32string_view = sprout::is_u32string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_u32string_view
: public sprout::is_u32string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#endif
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_basic_string_view_v = sprout::is_basic_string_view<T>::value;
template<typename T, typename Elem>
SPROUT_STATIC_CONSTEXPR bool is_string_view_of_v = sprout::is_string_view_of<T, Elem>::value;
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_string_view_v = sprout::is_string_view<T>::value;
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_wstring_view_v = sprout::is_wstring_view<T>::value;
#if SPROUT_USE_UNICODE_LITERALS
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_u16string_view_v = sprout::is_u16string_view<T>::value;
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_u32string_view_v = sprout::is_u32string_view<T>::value;
#endif
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_STRING_REF_ALIAS_HPP

View file

@ -9,6 +9,7 @@
#define SPROUT_UTILITY_STRING_REF_STRING_REF_HPP
#include <string>
#include <memory>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
@ -124,19 +125,19 @@ namespace sprout {
#else
SPROUT_CXX14_CONSTEXPR iterator
begin() SPROUT_NOEXCEPT {
return data();
return ptr_;
}
SPROUT_CONSTEXPR const_iterator
begin() const SPROUT_NOEXCEPT {
return data();
return ptr_;
}
SPROUT_CXX14_CONSTEXPR iterator
end() SPROUT_NOEXCEPT {
return data() + size();
return ptr_ + size();
}
SPROUT_CONSTEXPR const_iterator
end() const SPROUT_NOEXCEPT {
return data() + size();
return ptr_ + size();
}
#endif
SPROUT_CONSTEXPR const_reverse_iterator
@ -159,11 +160,11 @@ namespace sprout {
#else
SPROUT_CONSTEXPR const_iterator
cbegin() const SPROUT_NOEXCEPT {
return data();
return ptr_;
}
SPROUT_CONSTEXPR const_iterator
cend() const SPROUT_NOEXCEPT {
return data() + size();
return ptr_ + size();
}
#endif
SPROUT_CONSTEXPR const_reverse_iterator
@ -232,8 +233,8 @@ namespace sprout {
}
SPROUT_CONSTEXPR basic_string_ref
remove_prefix(size_type n) const {
return n > size() ? basic_string_ref(data() + size(), 0)
: basic_string_ref(data() + n, size() - n)
return n > size() ? basic_string_ref(ptr_ + size(), 0)
: basic_string_ref(ptr_ + n, size() - n)
;
}
SPROUT_CXX14_CONSTEXPR void
@ -245,8 +246,8 @@ namespace sprout {
}
SPROUT_CONSTEXPR basic_string_ref
remove_suffix(size_type n) const {
return n > size() ? basic_string_ref(data(), 0)
: basic_string_ref(data(), size() - n)
return n > size() ? basic_string_ref(ptr_, 0)
: basic_string_ref(ptr_, size() - n)
;
}
// string operations:
@ -355,6 +356,13 @@ namespace sprout {
find_last_not_of(value_type c, size_type pos = npos) const {
return sprout::string_detail::find_last_not_of_c_impl<basic_string_ref>(begin(), size(), c, pos);
}
SPROUT_CXX14_CONSTEXPR size_type
copy(value_type* s, size_type n, size_type pos = 0) const {
rangecheck(pos);
size_type llen = NS_SSCRISK_CEL_OR_SPROUT::min(n, size() - pos);
traits_type::copy(s, begin() + pos, llen);
return llen;
}
SPROUT_CONSTEXPR basic_string_ref
substr(size_type pos = 0, size_type n = npos) const {
return !(size() < pos) ? n == npos
@ -399,7 +407,7 @@ namespace sprout {
}
SPROUT_CONSTEXPR bool
starts_with(basic_string_ref const& str) const {
return size() >= str.size() && traits_type::compare(data(), str.data(), str.size()) == 0;
return size() >= str.size() && traits_type::compare(begin(), str.begin(), str.size()) == 0;
}
SPROUT_CONSTEXPR bool
ends_with(value_type c) const {
@ -407,24 +415,30 @@ namespace sprout {
}
SPROUT_CONSTEXPR bool
ends_with(basic_string_ref const& str) const {
return size() >= str.size() && traits_type::compare(data() + size() - str.size(), str.data(), str.size()) == 0;
return size() >= str.size() && traits_type::compare(begin() + size() - str.size(), str.begin(), str.size()) == 0;
}
template<std::size_t N>
SPROUT_NON_CONSTEXPR sprout::basic_string<T, N, Traits>
to_string() const {
return sprout::basic_string<T, N, Traits>(ptr_, size());
}
template<typename Allocator = std::allocator<T> >
SPROUT_NON_CONSTEXPR std::basic_string<T, Traits, Allocator>
to_string() const {
return std::basic_string<T, Traits, Allocator>(ptr_, size());
}
template<std::size_t N>
SPROUT_EXPLICIT_CONVERSION SPROUT_NON_CONSTEXPR operator sprout::basic_string<T, N, Traits>() const {
return to_string<N>();
}
// others:
template<typename Allocator>
SPROUT_EXPLICIT_CONVERSION SPROUT_NON_CONSTEXPR operator std::basic_string<T, Traits, Allocator>() const {
return std::basic_string<T, Traits, Allocator>(data(), size());
}
SPROUT_CONSTEXPR const_pointer
c_array() const SPROUT_NOEXCEPT {
return data();
}
SPROUT_CXX14_CONSTEXPR pointer
c_array() SPROUT_NOEXCEPT {
return data();
return to_string<Allocator>();
}
// others:
SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const {
return i >= size() ? throw std::out_of_range("uuid: index out of range")
SPROUT_CXX14_CONSTEXPR void
rangecheck(size_type i) const {
return i >= size() ? throw std::out_of_range("basic_string_ref<>: index out of range")
: (void)0
;
}

View file

@ -0,0 +1,189 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_UTILITY_STRING_REF_STRING_VIEW_HPP
#define SPROUT_UTILITY_STRING_REF_STRING_VIEW_HPP
#include <sprout/config.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/utility/string_ref/string_ref.hpp>
#include <sprout/utility/string_ref/type_traits.hpp>
namespace sprout {
//
// string_view
// wstring_view
// u16string_view
// u32string_view
//
typedef sprout::basic_string_ref<char> string_view;
typedef sprout::basic_string_ref<wchar_t> wstring_view;
#if SPROUT_USE_UNICODE_LITERALS
typedef sprout::basic_string_ref<char16_t> u16string_view;
typedef sprout::basic_string_ref<char32_t> u32string_view;
#endif
#if SPROUT_USE_TEMPLATE_ALIASES
//
// basic_string_view
//
template<typename T, typename Traits = sprout::char_traits<T> >
using basic_string_view = sprout::basic_string_ref<T, Traits>;
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// to_string_view
//
template<typename T, typename Traits>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T, Traits>
to_string_view(sprout::basic_string_ref<T, Traits> const& s) {
return sprout::to_string_ref(s);
}
template<typename T, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T, Traits>
to_string_view(sprout::basic_string<T, N, Traits> const& s) {
return sprout::to_string_ref(s);
}
template<typename T, typename Traits>
inline SPROUT_NON_CONSTEXPR sprout::basic_string_ref<T, Traits>
to_string_view(std::basic_string<T, Traits> const& s) {
return sprout::to_string_ref(s);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T>
to_string_view(T const* str) {
return sprout::to_string_ref(str);
}
template<typename T>
inline SPROUT_CONSTEXPR sprout::basic_string_ref<T>
to_string_view(T const* str, std::size_t len) {
return sprout::to_string_ref(str, len);
}
//
// is_basic_string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_basic_string_view = sprout::is_basic_string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
struct is_basic_string_view
: public sprout::is_basic_string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_string_view_of
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
using is_string_view_of = sprout::is_string_ref_of<T, Elem>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_string_view_of
: public sprout::is_string_ref_of<T, Elem>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_string_view = sprout::is_string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_string_view
: public sprout::is_string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_wstring_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_wstring_view = sprout::is_wstring_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_wstring_view
: public sprout::is_wstring_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#if SPROUT_USE_UNICODE_LITERALS
//
// is_u16string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_u16string_view = sprout::is_u16string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_u16string_view
: public sprout::is_u16string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
//
// is_u32string_view
//
#if SPROUT_USE_TEMPLATE_ALIASES
template<typename T>
using is_u32string_view = sprout::is_u32string_ref<T>;
#else // #if SPROUT_USE_TEMPLATE_ALIASES
template<typename T, typename Elem>
struct is_u32string_view
: public sprout::is_u32string_ref<T>
{};
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
#endif
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_basic_string_view_v = sprout::is_basic_string_view<T>::value;
template<typename T, typename Elem>
SPROUT_STATIC_CONSTEXPR bool is_string_view_of_v = sprout::is_string_view_of<T, Elem>::value;
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_string_view_v = sprout::is_string_view<T>::value;
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_wstring_view_v = sprout::is_wstring_view<T>::value;
#if SPROUT_USE_UNICODE_LITERALS
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_u16string_view_v = sprout::is_u16string_view<T>::value;
template<typename T>
SPROUT_STATIC_CONSTEXPR bool is_u32string_view_v = sprout::is_u32string_view<T>::value;
#endif
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
namespace udl {
//
// _sv
//
inline SPROUT_CONSTEXPR sprout::basic_string_ref<char>
operator"" _sv(char const* s, std::size_t size) {
return sprout::basic_string_ref<char>(s, size);
}
inline SPROUT_CONSTEXPR sprout::basic_string_ref<wchar_t>
operator"" _sv(wchar_t const* s, std::size_t size) {
return sprout::basic_string_ref<wchar_t>(s, size);
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::basic_string_ref<char16_t>
operator"" _sv(char16_t const* s, std::size_t size) {
return sprout::basic_string_ref<char16_t>(s, size);
}
inline SPROUT_CONSTEXPR sprout::basic_string_ref<char32_t>
operator"" _sv(char32_t const* s, std::size_t size) {
return sprout::basic_string_ref<char32_t>(s, size);
}
#endif
} // namespace udl
using sprout::udl::operator"" _sv;
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_STRING_REF_STRING_VIEW_HPP

View file

@ -0,0 +1,48 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_UTILITY_STRING_REF_UDL_HPP
#define SPROUT_UTILITY_STRING_REF_UDL_HPP
#include <sprout/config.hpp>
#include <sprout/utility/string_ref/string_ref.hpp>
#if SPROUT_USE_USER_DEFINED_LITERALS
#include <sprout/workaround/std/cstddef.hpp>
namespace sprout {
namespace udl {
//
// _sr
//
inline SPROUT_CONSTEXPR sprout::basic_string_ref<char>
operator"" _sr(char const* s, std::size_t size) {
return sprout::basic_string_ref<char>(s, size);
}
inline SPROUT_CONSTEXPR sprout::basic_string_ref<wchar_t>
operator"" _sr(wchar_t const* s, std::size_t size) {
return sprout::basic_string_ref<wchar_t>(s, size);
}
#if SPROUT_USE_UNICODE_LITERALS
inline SPROUT_CONSTEXPR sprout::basic_string_ref<char16_t>
operator"" _sr(char16_t const* s, std::size_t size) {
return sprout::basic_string_ref<char16_t>(s, size);
}
inline SPROUT_CONSTEXPR sprout::basic_string_ref<char32_t>
operator"" _sr(char32_t const* s, std::size_t size) {
return sprout::basic_string_ref<char32_t>(s, size);
}
#endif
} // namespace udl
using sprout::udl::operator"" _sr;
} // namespace sprout
#endif // #if SPROUT_USE_USER_DEFINED_LITERALS
#endif // #ifndef SPROUT_UTILITY_STRING_REF_UDL_HPP