diff --git a/sprout/string/shift_concat.hpp b/sprout/string/shift_concat.hpp index 83f9807e..bc97023c 100644 --- a/sprout/string/shift_concat.hpp +++ b/sprout/string/shift_concat.hpp @@ -77,6 +77,23 @@ namespace sprout { )... ); } + template + inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string + string_rshift( + sprout::basic_string const& lhs, std::size_t lsize, + std::initializer_list rhs, std::size_t rsize, + sprout::index_tuple + ) + { + typedef sprout::detail::string_construct_access access_type; + return access_type::raw_construct( + sprout::detail::checked_length(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::make() ); } + template + inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string + operator<<(sprout::basic_string const& lhs, std::initializer_list rhs) { + return sprout::detail::string_rshift( + lhs, lhs.size(), + rhs, rhs.size(), + sprout::make_index_tuple::make() + ); + } namespace detail { template @@ -161,6 +187,23 @@ namespace sprout { )... ); } + template + inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string + string_lshift( + sprout::basic_string const& lhs, std::size_t lsize, + std::initializer_list rhs, std::size_t rsize, + sprout::index_tuple + ) + { + typedef sprout::detail::string_construct_access access_type; + return access_type::raw_construct( + sprout::detail::checked_length(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::make() ); } + template + inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string + operator>>(sprout::basic_string const& lhs, std::initializer_list rhs) { + return sprout::detail::string_lshift( + lhs, lhs.size(), + rhs, rhs.size(), + sprout::make_index_tuple::make() + ); + } } // namespace sprout #endif // #ifndef SPROUT_STRING_SHIFT_CONCAT_HPP diff --git a/sprout/string/string.hpp b/sprout/string/string.hpp index 3d07843d..f302d10d 100644 --- a/sprout/string/string.hpp +++ b/sprout/string/string.hpp @@ -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) { + SPROUT_CXX14_CONSTEXPR void + put_terminator(size_type n) { + if (n < size()) { + traits_type::assign(begin() + n, size() - n, value_type()); + } impl_.len = n; - put_terminator(); } template - 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 - 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 - 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 - 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 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 - SPROUT_CXX14_CONSTEXPR basic_string& operator<<=(basic_string const& rhs) { + SPROUT_CXX14_CONSTEXPR basic_string& + operator<<=(basic_string const& rhs) { return append(rhs); } - SPROUT_CXX14_CONSTEXPR basic_string& operator>>=(T const& rhs) { + SPROUT_CXX14_CONSTEXPR basic_string& + operator<<=(std::initializer_list 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 - SPROUT_CXX14_CONSTEXPR basic_string& operator>>=(basic_string const& rhs) { + SPROUT_CXX14_CONSTEXPR basic_string& + operator>>=(basic_string 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 rhs) { lengthcheck(size() + rhs.size()); traits_type::move(begin() + rhs.size(), begin(), size()); traits_type::move(begin(), rhs.begin(), rhs.size()); diff --git a/sprout/utility/string_ref.hpp b/sprout/utility/string_ref.hpp index 4d2ff8e3..9c1c34c8 100644 --- a/sprout/utility/string_ref.hpp +++ b/sprout/utility/string_ref.hpp @@ -16,5 +16,7 @@ #include #include #include +#include +#include #endif // #ifndef SPROUT_UTILITY_STRING_REF_HPP diff --git a/sprout/utility/string_ref/alias.hpp b/sprout/utility/string_ref/alias.hpp index 415b6cbc..c2b10878 100644 --- a/sprout/utility/string_ref/alias.hpp +++ b/sprout/utility/string_ref/alias.hpp @@ -9,9 +9,7 @@ #define SPROUT_UTILITY_STRING_REF_ALIAS_HPP #include -#include #include -#include namespace sprout { // @@ -26,150 +24,6 @@ namespace sprout { typedef sprout::basic_string_ref u16string_ref; typedef sprout::basic_string_ref u32string_ref; #endif - // - // string_view - // wstring_view - // u16string_view - // u32string_view - // - typedef sprout::basic_string_ref string_view; - typedef sprout::basic_string_ref wstring_view; -#if SPROUT_USE_UNICODE_LITERALS - typedef sprout::basic_string_ref u16string_view; - typedef sprout::basic_string_ref u32string_view; -#endif - -#if SPROUT_USE_TEMPLATE_ALIASES - // - // basic_string_view - // - template > - using basic_string_view = sprout::basic_string_ref; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - - // - // to_string_view - // - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_view(sprout::basic_string_ref const& s) { - return sprout::to_string_ref(s); - } - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_view(sprout::basic_string const& s) { - return sprout::to_string_ref(s); - } - template - inline SPROUT_NON_CONSTEXPR sprout::basic_string_ref - to_string_view(std::basic_string const& s) { - return sprout::to_string_ref(s); - } - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - to_string_view(T const* str) { - return sprout::to_string_ref(str); - } - template - inline SPROUT_CONSTEXPR sprout::basic_string_ref - 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 - using is_basic_string_view = sprout::is_basic_string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_basic_string_view - : public sprout::is_basic_string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - - // - // is_string_view_of - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_string_view_of = sprout::is_string_ref_of; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_string_view_of - : public sprout::is_string_ref_of - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - - // - // is_string_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_string_view = sprout::is_string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_string_view - : public sprout::is_string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - // - // is_wstring_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_wstring_view = sprout::is_wstring_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_wstring_view - : public sprout::is_wstring_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - -#if SPROUT_USE_UNICODE_LITERALS - // - // is_u16string_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_u16string_view = sprout::is_u16string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_u16string_view - : public sprout::is_u16string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES - // - // is_u32string_view - // -#if SPROUT_USE_TEMPLATE_ALIASES - template - using is_u32string_view = sprout::is_u32string_ref; -#else // #if SPROUT_USE_TEMPLATE_ALIASES - template - struct is_u32string_view - : public sprout::is_u32string_ref - {}; -#endif // #if SPROUT_USE_TEMPLATE_ALIASES -#endif - -#if SPROUT_USE_VARIABLE_TEMPLATES - template - SPROUT_STATIC_CONSTEXPR bool is_basic_string_view_v = sprout::is_basic_string_view::value; - template - SPROUT_STATIC_CONSTEXPR bool is_string_view_of_v = sprout::is_string_view_of::value; - template - SPROUT_STATIC_CONSTEXPR bool is_string_view_v = sprout::is_string_view::value; - template - SPROUT_STATIC_CONSTEXPR bool is_wstring_view_v = sprout::is_wstring_view::value; -#if SPROUT_USE_UNICODE_LITERALS - template - SPROUT_STATIC_CONSTEXPR bool is_u16string_view_v = sprout::is_u16string_view::value; - template - SPROUT_STATIC_CONSTEXPR bool is_u32string_view_v = sprout::is_u32string_view::value; -#endif -#endif // #if SPROUT_USE_VARIABLE_TEMPLATES } // namespace sprout #endif // #ifndef SPROUT_UTILITY_STRING_REF_ALIAS_HPP diff --git a/sprout/utility/string_ref/string_ref.hpp b/sprout/utility/string_ref/string_ref.hpp index 13dc77ff..84daf12a 100644 --- a/sprout/utility/string_ref/string_ref.hpp +++ b/sprout/utility/string_ref/string_ref.hpp @@ -9,6 +9,7 @@ #define SPROUT_UTILITY_STRING_REF_STRING_REF_HPP #include +#include #include #include #include @@ -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(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 + SPROUT_NON_CONSTEXPR sprout::basic_string + to_string() const { + return sprout::basic_string(ptr_, size()); + } + template > + SPROUT_NON_CONSTEXPR std::basic_string + to_string() const { + return std::basic_string(ptr_, size()); + } + template + SPROUT_EXPLICIT_CONVERSION SPROUT_NON_CONSTEXPR operator sprout::basic_string() const { + return to_string(); } - // others: template SPROUT_EXPLICIT_CONVERSION SPROUT_NON_CONSTEXPR operator std::basic_string() const { - return std::basic_string(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(); } // 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 ; } diff --git a/sprout/utility/string_ref/string_view.hpp b/sprout/utility/string_ref/string_view.hpp new file mode 100644 index 00000000..da959c27 --- /dev/null +++ b/sprout/utility/string_ref/string_view.hpp @@ -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 +#include +#include +#include + +namespace sprout { + // + // string_view + // wstring_view + // u16string_view + // u32string_view + // + typedef sprout::basic_string_ref string_view; + typedef sprout::basic_string_ref wstring_view; +#if SPROUT_USE_UNICODE_LITERALS + typedef sprout::basic_string_ref u16string_view; + typedef sprout::basic_string_ref u32string_view; +#endif + +#if SPROUT_USE_TEMPLATE_ALIASES + // + // basic_string_view + // + template > + using basic_string_view = sprout::basic_string_ref; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + + // + // to_string_view + // + template + inline SPROUT_CONSTEXPR sprout::basic_string_ref + to_string_view(sprout::basic_string_ref const& s) { + return sprout::to_string_ref(s); + } + template + inline SPROUT_CONSTEXPR sprout::basic_string_ref + to_string_view(sprout::basic_string const& s) { + return sprout::to_string_ref(s); + } + template + inline SPROUT_NON_CONSTEXPR sprout::basic_string_ref + to_string_view(std::basic_string const& s) { + return sprout::to_string_ref(s); + } + template + inline SPROUT_CONSTEXPR sprout::basic_string_ref + to_string_view(T const* str) { + return sprout::to_string_ref(str); + } + template + inline SPROUT_CONSTEXPR sprout::basic_string_ref + 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 + using is_basic_string_view = sprout::is_basic_string_ref; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_basic_string_view + : public sprout::is_basic_string_ref + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + + // + // is_string_view_of + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_string_view_of = sprout::is_string_ref_of; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_string_view_of + : public sprout::is_string_ref_of + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + + // + // is_string_view + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_string_view = sprout::is_string_ref; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_string_view + : public sprout::is_string_ref + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + // + // is_wstring_view + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_wstring_view = sprout::is_wstring_ref; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_wstring_view + : public sprout::is_wstring_ref + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_UNICODE_LITERALS + // + // is_u16string_view + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_u16string_view = sprout::is_u16string_ref; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_u16string_view + : public sprout::is_u16string_ref + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + // + // is_u32string_view + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_u32string_view = sprout::is_u32string_ref; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct is_u32string_view + : public sprout::is_u32string_ref + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES +#endif + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_basic_string_view_v = sprout::is_basic_string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_string_view_of_v = sprout::is_string_view_of::value; + template + SPROUT_STATIC_CONSTEXPR bool is_string_view_v = sprout::is_string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_wstring_view_v = sprout::is_wstring_view::value; +#if SPROUT_USE_UNICODE_LITERALS + template + SPROUT_STATIC_CONSTEXPR bool is_u16string_view_v = sprout::is_u16string_view::value; + template + SPROUT_STATIC_CONSTEXPR bool is_u32string_view_v = sprout::is_u32string_view::value; +#endif +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + + namespace udl { + // + // _sv + // + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sv(char const* s, std::size_t size) { + return sprout::basic_string_ref(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sv(wchar_t const* s, std::size_t size) { + return sprout::basic_string_ref(s, size); + } +#if SPROUT_USE_UNICODE_LITERALS + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sv(char16_t const* s, std::size_t size) { + return sprout::basic_string_ref(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sv(char32_t const* s, std::size_t size) { + return sprout::basic_string_ref(s, size); + } +#endif + } // namespace udl + + using sprout::udl::operator"" _sv; +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_STRING_REF_STRING_VIEW_HPP diff --git a/sprout/utility/string_ref/udl.hpp b/sprout/utility/string_ref/udl.hpp new file mode 100644 index 00000000..2c464473 --- /dev/null +++ b/sprout/utility/string_ref/udl.hpp @@ -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 +#include + +#if SPROUT_USE_USER_DEFINED_LITERALS + +#include + +namespace sprout { + namespace udl { + // + // _sr + // + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sr(char const* s, std::size_t size) { + return sprout::basic_string_ref(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sr(wchar_t const* s, std::size_t size) { + return sprout::basic_string_ref(s, size); + } +#if SPROUT_USE_UNICODE_LITERALS + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sr(char16_t const* s, std::size_t size) { + return sprout::basic_string_ref(s, size); + } + inline SPROUT_CONSTEXPR sprout::basic_string_ref + operator"" _sr(char32_t const* s, std::size_t size) { + return sprout::basic_string_ref(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