11 #ifndef NONSTD_SV_LITE_H_INCLUDED 12 #define NONSTD_SV_LITE_H_INCLUDED 14 #define string_view_lite_MAJOR 1 15 #define string_view_lite_MINOR 1 16 #define string_view_lite_PATCH 0 18 #define string_view_lite_VERSION nssv_STRINGIFY(string_view_lite_MAJOR) "." nssv_STRINGIFY(string_view_lite_MINOR) "." nssv_STRINGIFY(string_view_lite_PATCH) 20 #define nssv_STRINGIFY( x ) nssv_STRINGIFY_( x ) 21 #define nssv_STRINGIFY_( x ) #x 25 #define nssv_STRING_VIEW_DEFAULT 0 26 #define nssv_STRING_VIEW_NONSTD 1 27 #define nssv_STRING_VIEW_STD 2 29 #if !defined( nssv_CONFIG_SELECT_STRING_VIEW ) 30 # define nssv_CONFIG_SELECT_STRING_VIEW ( nssv_HAVE_STD_STRING_VIEW ? nssv_STRING_VIEW_STD : nssv_STRING_VIEW_NONSTD ) 33 #if defined( nssv_CONFIG_SELECT_STD_STRING_VIEW ) || defined( nssv_CONFIG_SELECT_NONSTD_STRING_VIEW ) 34 # error nssv_CONFIG_SELECT_STD_STRING_VIEW and nssv_CONFIG_SELECT_NONSTD_STRING_VIEW are deprecated and removed, please use nssv_CONFIG_SELECT_STRING_VIEW=nssv_STRING_VIEW_... 37 #ifndef nssv_CONFIG_STD_SV_OPERATOR 38 # define nssv_CONFIG_STD_SV_OPERATOR 0 41 #ifndef nssv_CONFIG_USR_SV_OPERATOR 42 # define nssv_CONFIG_USR_SV_OPERATOR 1 45 #ifdef nssv_CONFIG_CONVERSION_STD_STRING 46 # define nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS nssv_CONFIG_CONVERSION_STD_STRING 47 # define nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS nssv_CONFIG_CONVERSION_STD_STRING 50 #ifndef nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS 51 # define nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS 1 54 #ifndef nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 55 # define nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1 61 #ifndef nssv_CPLUSPLUS 62 # if defined(_MSVC_LANG ) && !defined(__clang__) 63 # define nssv_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) 65 # define nssv_CPLUSPLUS __cplusplus 69 #define nssv_CPP98_OR_GREATER ( nssv_CPLUSPLUS >= 199711L ) 70 #define nssv_CPP11_OR_GREATER ( nssv_CPLUSPLUS >= 201103L ) 71 #define nssv_CPP11_OR_GREATER_ ( nssv_CPLUSPLUS >= 201103L ) 72 #define nssv_CPP14_OR_GREATER ( nssv_CPLUSPLUS >= 201402L ) 73 #define nssv_CPP17_OR_GREATER ( nssv_CPLUSPLUS >= 201703L ) 74 #define nssv_CPP20_OR_GREATER ( nssv_CPLUSPLUS >= 202000L ) 78 #if nssv_CPP17_OR_GREATER && defined(__has_include ) 79 # if __has_include( <string_view> ) 80 # define nssv_HAVE_STD_STRING_VIEW 1 82 # define nssv_HAVE_STD_STRING_VIEW 0 85 # define nssv_HAVE_STD_STRING_VIEW 0 88 #define nssv_USES_STD_STRING_VIEW ( (nssv_CONFIG_SELECT_STRING_VIEW == nssv_STRING_VIEW_STD) || ((nssv_CONFIG_SELECT_STRING_VIEW == nssv_STRING_VIEW_DEFAULT) && nssv_HAVE_STD_STRING_VIEW) ) 90 #define nssv_HAVE_STARTS_WITH ( nssv_CPP20_OR_GREATER || !nssv_USES_STD_STRING_VIEW ) 91 #define nssv_HAVE_ENDS_WITH nssv_HAVE_STARTS_WITH 97 #if nssv_USES_STD_STRING_VIEW 99 #include <string_view> 103 #if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 107 template<
class CharT,
class Traits,
class Allocator = std::allocator<CharT> >
108 std::basic_string<CharT, Traits, Allocator>
109 to_string( std::basic_string_view<CharT, Traits> v, Allocator
const & a = Allocator() )
111 return std::basic_string<CharT,Traits, Allocator>( v.begin(), v.end(), a );
114 template<
class CharT,
class Traits,
class Allocator >
115 std::basic_string_view<CharT, Traits>
116 to_string_view( std::basic_string<CharT, Traits, Allocator>
const & s )
118 return std::basic_string_view<CharT, Traits>( s.data(), s.size() );
123 #if nssv_CONFIG_STD_SV_OPERATOR 125 using namespace std::literals::string_view_literals;
129 #if nssv_CONFIG_USR_SV_OPERATOR 131 inline namespace literals {
132 inline namespace string_view_literals {
135 constexpr std::string_view
operator "" _sv(
const char* str,
size_t len ) noexcept
137 return std::string_view{ str, len };
140 constexpr std::u16string_view
operator "" _sv(
const char16_t* str,
size_t len ) noexcept
142 return std::u16string_view{ str, len };
145 constexpr std::u32string_view
operator "" _sv(
const char32_t* str,
size_t len ) noexcept
147 return std::u32string_view{ str, len };
150 constexpr std::wstring_view
operator "" _sv(
const wchar_t* str,
size_t len ) noexcept
152 return std::wstring_view{ str, len };
157 #endif // nssv_CONFIG_USR_SV_OPERATOR 161 #endif // nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 165 using std::string_view;
166 using std::wstring_view;
167 using std::u16string_view;
168 using std::u32string_view;
169 using std::basic_string_view;
173 using std::operator==;
174 using std::operator!=;
175 using std::operator<;
176 using std::operator<=;
177 using std::operator>;
178 using std::operator>=;
180 using std::operator<<;
184 #else // nssv_HAVE_STD_STRING_VIEW 203 #if defined(_MSC_VER ) && !defined(__clang__) 204 # define nssv_COMPILER_MSVC_VER (_MSC_VER ) 205 # define nssv_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) 207 # define nssv_COMPILER_MSVC_VER 0 208 # define nssv_COMPILER_MSVC_VERSION 0 211 #define nssv_COMPILER_VERSION( major, minor, patch ) (10 * ( 10 * major + minor) + patch) 213 #if defined(__clang__) 214 # define nssv_COMPILER_CLANG_VERSION nssv_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) 216 # define nssv_COMPILER_CLANG_VERSION 0 219 #if defined(__GNUC__) && !defined(__clang__) 220 # define nssv_COMPILER_GNUC_VERSION nssv_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) 222 # define nssv_COMPILER_GNUC_VERSION 0 226 #define nssv_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) 231 # define nssv_HAS_CPP0X _HAS_CPP0X 233 # define nssv_HAS_CPP0X 0 238 #if nssv_COMPILER_MSVC_VER >= 1900 239 # undef nssv_CPP11_OR_GREATER 240 # define nssv_CPP11_OR_GREATER 1 243 #define nssv_CPP11_90 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1500) 244 #define nssv_CPP11_100 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1600) 245 #define nssv_CPP11_110 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1700) 246 #define nssv_CPP11_120 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1800) 247 #define nssv_CPP11_140 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1900) 248 #define nssv_CPP11_141 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1910) 250 #define nssv_CPP14_000 (nssv_CPP14_OR_GREATER) 251 #define nssv_CPP17_000 (nssv_CPP17_OR_GREATER) 255 #define nssv_HAVE_CONSTEXPR_11 nssv_CPP11_140 256 #define nssv_HAVE_EXPLICIT_CONVERSION nssv_CPP11_140 257 #define nssv_HAVE_INLINE_NAMESPACE nssv_CPP11_140 258 #define nssv_HAVE_NOEXCEPT nssv_CPP11_140 259 #define nssv_HAVE_NULLPTR nssv_CPP11_100 260 #define nssv_HAVE_REF_QUALIFIER nssv_CPP11_140 261 #define nssv_HAVE_UNICODE_LITERALS nssv_CPP11_140 262 #define nssv_HAVE_USER_DEFINED_LITERALS nssv_CPP11_140 263 #define nssv_HAVE_WCHAR16_T nssv_CPP11_100 264 #define nssv_HAVE_WCHAR32_T nssv_CPP11_100 266 #if ! ( ( nssv_CPP11 && nssv_COMPILER_CLANG_VERSION ) || nssv_BETWEEN( nssv_COMPILER_CLANG_VERSION, 300, 400 ) ) 267 # define nssv_HAVE_STD_DEFINED_LITERALS nssv_CPP11_140 272 #define nssv_HAVE_CONSTEXPR_14 nssv_CPP14_000 276 #define nssv_HAVE_NODISCARD nssv_CPP17_000 280 #define nssv_HAVE_STD_HASH nssv_CPP11_120 284 #if nssv_HAVE_CONSTEXPR_11 285 # define nssv_constexpr constexpr 287 # define nssv_constexpr 290 #if nssv_HAVE_CONSTEXPR_14 291 # define nssv_constexpr14 constexpr 293 # define nssv_constexpr14 296 #if nssv_HAVE_EXPLICIT_CONVERSION 297 # define nssv_explicit explicit 299 # define nssv_explicit 302 #if nssv_HAVE_INLINE_NAMESPACE 303 # define nssv_inline_ns inline 305 # define nssv_inline_ns 308 #if nssv_HAVE_NOEXCEPT 309 # define nssv_noexcept noexcept 311 # define nssv_noexcept 322 #if nssv_HAVE_NULLPTR 323 # define nssv_nullptr nullptr 325 # define nssv_nullptr NULL 328 #if nssv_HAVE_NODISCARD 329 # define nssv_nodiscard [[nodiscard]] 331 # define nssv_nodiscard 344 #if nssv_CPP11_OR_GREATER 345 # include <type_traits> 350 #if defined(__clang__) 351 # pragma clang diagnostic ignored "-Wreserved-user-defined-literal" 352 # pragma clang diagnostic push 353 # pragma clang diagnostic ignored "-Wuser-defined-literals" 354 #elif defined(__GNUC__) 355 # pragma GCC diagnostic push 356 # pragma GCC diagnostic ignored "-Wliteral-suffix" 359 #if nssv_COMPILER_MSVC_VERSION >= 140 360 # define nssv_SUPPRESS_MSGSL_WARNING(expr) [[gsl::suppress(expr)]] 361 # define nssv_SUPPRESS_MSVC_WARNING(code, descr) __pragma(warning(suppress: code) ) 362 # define nssv_DISABLE_MSVC_WARNINGS(codes) __pragma(warning(push)) __pragma(warning(disable: codes)) 364 # define nssv_SUPPRESS_MSGSL_WARNING(expr) 365 # define nssv_SUPPRESS_MSVC_WARNING(code, descr) 366 # define nssv_DISABLE_MSVC_WARNINGS(codes) 369 #if defined(__clang__) 370 # define nssv_RESTORE_WARNINGS() _Pragma("clang diagnostic pop") 371 #elif defined(__GNUC__) 372 # define nssv_RESTORE_WARNINGS() _Pragma("GCC diagnostic pop") 373 #elif nssv_COMPILER_MSVC_VERSION >= 140 374 # define nssv_RESTORE_WARNINGS() __pragma(warning(pop )) 376 # define nssv_RESTORE_WARNINGS() 390 namespace
nonstd {
namespace sv_lite {
395 class Traits = std::char_traits<CharT>
397 class basic_string_view;
408 class basic_string_view
413 typedef Traits traits_type;
414 typedef CharT value_type;
416 typedef CharT * pointer;
417 typedef CharT
const * const_pointer;
418 typedef CharT & reference;
419 typedef CharT
const & const_reference;
421 typedef const_pointer iterator;
422 typedef const_pointer const_iterator;
423 typedef std::reverse_iterator< const_iterator > reverse_iterator;
424 typedef std::reverse_iterator< const_iterator > const_reverse_iterator;
426 typedef std::size_t size_type;
427 typedef std::ptrdiff_t difference_type;
436 #if nssv_CPP11_OR_GREATER 439 nssv_constexpr basic_string_view( basic_string_view
const & other ) nssv_noexcept
440 : data_( other.data_)
441 , size_( other.size_)
452 , size_( Traits::length(s) )
457 #if nssv_CPP11_OR_GREATER 458 nssv_constexpr14 basic_string_view & operator=( basic_string_view
const & other ) nssv_noexcept =
default;
460 nssv_constexpr14 basic_string_view & operator=( basic_string_view
const & other ) nssv_noexcept
470 nssv_constexpr const_iterator begin()
const nssv_noexcept {
return data_; }
471 nssv_constexpr const_iterator end()
const nssv_noexcept {
return data_ + size_; }
473 nssv_constexpr const_iterator cbegin()
const nssv_noexcept {
return begin(); }
474 nssv_constexpr const_iterator cend()
const nssv_noexcept {
return end(); }
476 nssv_constexpr const_reverse_iterator rbegin()
const nssv_noexcept {
return const_reverse_iterator( end() ); }
477 nssv_constexpr const_reverse_iterator rend()
const nssv_noexcept {
return const_reverse_iterator( begin() ); }
479 nssv_constexpr const_reverse_iterator crbegin()
const nssv_noexcept {
return rbegin(); }
480 nssv_constexpr const_reverse_iterator crend()
const nssv_noexcept {
return rend(); }
484 nssv_constexpr size_type size()
const nssv_noexcept {
return size_; }
485 nssv_constexpr size_type length()
const nssv_noexcept {
return size_; }
486 nssv_constexpr size_type max_size()
const nssv_noexcept {
return (std::numeric_limits< size_type >::max)(); }
498 return data_at( pos );
505 return data_at( pos );
508 throw std::out_of_range(
"nonst::string_view::at()");
511 nssv_constexpr const_reference front()
const {
return data_at( 0 ); }
512 nssv_constexpr const_reference back()
const {
return data_at( size() - 1 ); }
520 assert( n <= size() );
527 assert( n <= size() );
534 swap( data_, other.data_ );
535 swap( size_, other.size_ );
540 size_type copy( CharT * dest, size_type n, size_type pos = 0 )
const 543 throw std::out_of_range(
"nonst::string_view::copy()");
545 const size_type rlen = (std::min)( n, size() - pos );
547 (void) Traits::copy( dest,
data() + pos, rlen );
552 nssv_constexpr14 basic_string_view substr( size_type pos = 0, size_type n = npos )
const 555 throw std::out_of_range(
"nonst::string_view::substr()");
557 return basic_string_view(
data() + pos, (std::min)( n, size() - pos ) );
564 if (
const int result = Traits::compare(
data(), other.data(), (std::min)( size(), other.size() ) ) )
567 return size() == other.size() ? 0 : size() < other.size() ? -1 : 1;
570 nssv_constexpr int compare( size_type pos1, size_type n1, basic_string_view other )
const 572 return substr( pos1, n1 ).compare( other );
575 nssv_constexpr int compare( size_type pos1, size_type n1, basic_string_view other, size_type pos2, size_type n2 )
const 577 return substr( pos1, n1 ).compare( other.substr( pos2, n2 ) );
582 return compare( basic_string_view( s ) );
585 nssv_constexpr int compare( size_type pos1, size_type n1, CharT
const * s )
const 587 return substr( pos1, n1 ).compare( basic_string_view( s ) );
590 nssv_constexpr int compare( size_type pos1, size_type n1, CharT
const * s, size_type n2 )
const 592 return substr( pos1, n1 ).compare( basic_string_view( s, n2 ) );
599 nssv_constexpr bool starts_with( basic_string_view v )
const nssv_noexcept
601 return size() >= v.size() && compare( 0, v.size(), v ) == 0;
606 return starts_with( basic_string_view( &c, 1 ) );
611 return starts_with( basic_string_view( s ) );
616 nssv_constexpr bool ends_with( basic_string_view v )
const nssv_noexcept
618 return size() >= v.size() && compare( size() - v.size(), npos, v ) == 0;
623 return ends_with( basic_string_view( &c, 1 ) );
628 return ends_with( basic_string_view( s ) );
633 nssv_constexpr14 size_type find( basic_string_view v, size_type pos = 0 )
const nssv_noexcept
635 return assert( v.size() == 0 || v.data() !=
nssv_nullptr )
638 : to_pos( std::search( cbegin() + pos, cend(), v.cbegin(), v.cend(), Traits::eq ) );
641 nssv_constexpr14 size_type find( CharT c, size_type pos = 0 )
const nssv_noexcept
643 return find( basic_string_view( &c, 1 ), pos );
646 nssv_constexpr14 size_type find( CharT
const * s, size_type pos, size_type n )
const 648 return find( basic_string_view( s, n ), pos );
653 return find( basic_string_view( s ), pos );
658 nssv_constexpr14 size_type rfind( basic_string_view v, size_type pos = npos )
const nssv_noexcept
660 if ( size() < v.size() )
664 return (std::min)( size(), pos );
666 const_iterator last = cbegin() + (std::min)( size() - v.size(), pos ) + v.size();
667 const_iterator result = std::find_end( cbegin(), last, v.cbegin(), v.cend(), Traits::eq );
669 return result != last ? size_type( result - cbegin() ) : npos;
672 nssv_constexpr14 size_type rfind( CharT c, size_type pos = npos )
const nssv_noexcept
674 return rfind( basic_string_view( &c, 1 ), pos );
677 nssv_constexpr14 size_type rfind( CharT
const * s, size_type pos, size_type n )
const 679 return rfind( basic_string_view( s, n ), pos );
682 nssv_constexpr14 size_type rfind( CharT
const * s, size_type pos = npos )
const 684 return rfind( basic_string_view( s ), pos );
689 nssv_constexpr size_type find_first_of( basic_string_view v, size_type pos = 0 )
const nssv_noexcept
693 : to_pos( std::find_first_of( cbegin() + pos, cend(), v.cbegin(), v.cend(), Traits::eq ) );
696 nssv_constexpr size_type find_first_of( CharT c, size_type pos = 0 )
const nssv_noexcept
698 return find_first_of( basic_string_view( &c, 1 ), pos );
701 nssv_constexpr size_type find_first_of( CharT
const * s, size_type pos, size_type n )
const 703 return find_first_of( basic_string_view( s, n ), pos );
706 nssv_constexpr size_type find_first_of( CharT
const * s, size_type pos = 0 )
const 708 return find_first_of( basic_string_view( s ), pos );
713 nssv_constexpr size_type find_last_of( basic_string_view v, size_type pos = npos )
const nssv_noexcept
716 ? find_last_of( v, size() - 1 )
717 : to_pos( std::find_first_of( const_reverse_iterator( cbegin() + pos + 1 ), crend(), v.cbegin(), v.cend(), Traits::eq ) );
720 nssv_constexpr size_type find_last_of( CharT c, size_type pos = npos )
const nssv_noexcept
722 return find_last_of( basic_string_view( &c, 1 ), pos );
725 nssv_constexpr size_type find_last_of( CharT
const * s, size_type pos, size_type count )
const 727 return find_last_of( basic_string_view( s, count ), pos );
730 nssv_constexpr size_type find_last_of( CharT
const * s, size_type pos = npos )
const 732 return find_last_of( basic_string_view( s ), pos );
737 nssv_constexpr size_type find_first_not_of( basic_string_view v, size_type pos = 0 )
const nssv_noexcept
741 : to_pos( std::find_if( cbegin() + pos, cend(), not_in_view( v ) ) );
744 nssv_constexpr size_type find_first_not_of( CharT c, size_type pos = 0 )
const nssv_noexcept
746 return find_first_not_of( basic_string_view( &c, 1 ), pos );
749 nssv_constexpr size_type find_first_not_of( CharT
const * s, size_type pos, size_type count )
const 751 return find_first_not_of( basic_string_view( s, count ), pos );
754 nssv_constexpr size_type find_first_not_of( CharT
const * s, size_type pos = 0 )
const 756 return find_first_not_of( basic_string_view( s ), pos );
761 nssv_constexpr size_type find_last_not_of( basic_string_view v, size_type pos = npos )
const nssv_noexcept
764 ? find_last_not_of( v, size() - 1 )
765 : to_pos( std::find_if( const_reverse_iterator( cbegin() + pos + 1 ), crend(), not_in_view( v ) ) );
768 nssv_constexpr size_type find_last_not_of( CharT c, size_type pos = npos )
const nssv_noexcept
770 return find_last_not_of( basic_string_view( &c, 1 ), pos );
773 nssv_constexpr size_type find_last_not_of( CharT
const * s, size_type pos, size_type count )
const 775 return find_last_not_of( basic_string_view( s, count ), pos );
778 nssv_constexpr size_type find_last_not_of( CharT
const * s, size_type pos = npos )
const 780 return find_last_not_of( basic_string_view( s ), pos );
785 #if nssv_CPP17_OR_GREATER 787 #elif nssv_CPP11_OR_GREATER 788 enum : size_type { npos = size_type(-1) };
790 enum { npos = size_type(-1) };
796 const basic_string_view v;
802 return npos == v.find_first_of( c );
808 return it == cend() ? npos : size_type( it - cbegin() );
811 nssv_constexpr size_type to_pos( const_reverse_iterator it )
const 813 return it == crend() ? npos : size_type( crend() - it - 1 );
818 #if nssv_BETWEEN( nssv_COMPILER_GNUC_VERSION, 1, 500 ) 821 return assert( pos < size() ), data_[pos];
830 #if nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS 832 template<
class Allocator >
833 basic_string_view( std::basic_string<CharT, Traits, Allocator>
const & s ) nssv_noexcept
838 #if nssv_HAVE_EXPLICIT_CONVERSION 840 template<
class Allocator >
841 explicit operator std::basic_string<CharT, Traits, Allocator>()
const 846 #endif // nssv_HAVE_EXPLICIT_CONVERSION 848 #if nssv_CPP11_OR_GREATER 850 template<
class Allocator = std::allocator<CharT> >
851 std::basic_string<CharT, Traits, Allocator>
852 to_string( Allocator
const & a = Allocator() )
const 854 return std::basic_string<CharT, Traits, Allocator>( begin(), end(), a );
859 std::basic_string<CharT, Traits>
862 return std::basic_string<CharT, Traits>( begin(), end() );
865 template<
class Allocator >
866 std::basic_string<CharT, Traits, Allocator>
869 return std::basic_string<CharT, Traits, Allocator>( begin(), end(), a );
872 #endif // nssv_CPP11_OR_GREATER 874 #endif // nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS 884 template<
class CharT,
class Traits >
886 basic_string_view <CharT, Traits> lhs,
888 {
return lhs.compare( rhs ) == 0 ; }
890 template<
class CharT,
class Traits >
892 basic_string_view <CharT, Traits> lhs,
894 {
return lhs.compare( rhs ) != 0 ; }
896 template<
class CharT,
class Traits >
898 basic_string_view <CharT, Traits> lhs,
900 {
return lhs.compare( rhs ) < 0 ; }
902 template<
class CharT,
class Traits >
904 basic_string_view <CharT, Traits> lhs,
906 {
return lhs.compare( rhs ) <= 0 ; }
908 template<
class CharT,
class Traits >
910 basic_string_view <CharT, Traits> lhs,
912 {
return lhs.compare( rhs ) > 0 ; }
914 template<
class CharT,
class Traits >
916 basic_string_view <CharT, Traits> lhs,
918 {
return lhs.compare( rhs ) >= 0 ; }
925 #if nssv_CPP11_OR_GREATER && ! nssv_BETWEEN( nssv_COMPILER_MSVC_VERSION, 100, 141 ) 927 #define nssv_BASIC_STRING_VIEW_I(T,U) typename std::decay< basic_string_view<T,U> >::type 929 #if nssv_BETWEEN( nssv_COMPILER_MSVC_VERSION, 140, 150 ) 930 # define nssv_MSVC_ORDER(x) , int=x 932 # define nssv_MSVC_ORDER(x) 937 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
939 basic_string_view <CharT, Traits> lhs,
941 {
return lhs.compare( rhs ) == 0; }
943 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
945 nssv_BASIC_STRING_VIEW_I(CharT, Traits) lhs,
947 {
return lhs.compare( rhs ) == 0; }
951 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
953 basic_string_view < CharT, Traits > lhs,
954 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 955 {
return lhs.compare( rhs ) != 0 ; }
957 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
959 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
961 {
return lhs.compare( rhs ) != 0 ; }
965 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
967 basic_string_view < CharT, Traits > lhs,
968 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 969 {
return lhs.compare( rhs ) < 0 ; }
971 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
973 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
975 {
return lhs.compare( rhs ) < 0 ; }
979 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
981 basic_string_view < CharT, Traits > lhs,
982 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 983 {
return lhs.compare( rhs ) <= 0 ; }
985 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
987 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
989 {
return lhs.compare( rhs ) <= 0 ; }
993 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
995 basic_string_view < CharT, Traits > lhs,
996 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 997 {
return lhs.compare( rhs ) > 0 ; }
999 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
1001 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
1003 {
return lhs.compare( rhs ) > 0 ; }
1007 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
1009 basic_string_view < CharT, Traits > lhs,
1010 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 1011 {
return lhs.compare( rhs ) >= 0 ; }
1013 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
1015 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
1017 {
return lhs.compare( rhs ) >= 0 ; }
1019 #undef nssv_MSVC_ORDER 1020 #undef nssv_BASIC_STRING_VIEW_I 1022 #endif // nssv_CPP11_OR_GREATER 1028 template<
class Stream >
1029 void write_padding( Stream & os, std::streamsize n )
1031 for ( std::streamsize i = 0; i < n; ++i )
1032 os.rdbuf()->sputc( os.fill() );
1035 template<
class Stream,
class View >
1036 Stream & write_to_stream( Stream & os, View
const & sv )
1038 typename Stream::sentry sentry( os );
1043 const std::streamsize length =
static_cast<std::streamsize
>( sv.length() );
1046 const bool pad = ( length < os.width() );
1047 const bool left_pad = pad && ( os.flags() & std::ios_base::adjustfield ) == std::ios_base::right;
1050 write_padding( os, os.width() - length );
1053 os.rdbuf()->sputn( sv.begin(), length );
1055 if ( pad && !left_pad )
1056 write_padding( os, os.width() - length );
1066 template<
class CharT,
class Traits >
1067 std::basic_ostream<CharT, Traits> &
1069 std::basic_ostream<CharT, Traits>& os,
1070 basic_string_view <CharT, Traits> sv )
1072 return detail::write_to_stream( os, sv );
1077 typedef basic_string_view<char> string_view;
1078 typedef basic_string_view<wchar_t> wstring_view;
1079 #if nssv_HAVE_WCHAR16_T 1080 typedef basic_string_view<char16_t> u16string_view;
1081 typedef basic_string_view<char32_t> u32string_view;
1090 #if nssv_HAVE_USER_DEFINED_LITERALS 1096 #if nssv_CONFIG_STD_SV_OPERATOR && nssv_HAVE_STD_DEFINED_LITERALS 1100 return nonstd::sv_lite::string_view{ str, len };
1105 return nonstd::sv_lite::u16string_view{ str, len };
1110 return nonstd::sv_lite::u32string_view{ str, len };
1115 return nonstd::sv_lite::wstring_view{ str, len };
1118 #endif // nssv_CONFIG_STD_SV_OPERATOR && nssv_HAVE_STD_DEFINED_LITERALS 1120 #if nssv_CONFIG_USR_SV_OPERATOR 1124 return nonstd::sv_lite::string_view{ str, len };
1129 return nonstd::sv_lite::u16string_view{ str, len };
1134 return nonstd::sv_lite::u32string_view{ str, len };
1139 return nonstd::sv_lite::wstring_view{ str, len };
1142 #endif // nssv_CONFIG_USR_SV_OPERATOR 1152 #if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1159 #if nssv_CPP11_OR_GREATER && nssv_COMPILER_MSVC_VERSION != 140 1161 template<
class CharT,
class Traits,
class Allocator = std::allocator<CharT> >
1162 std::basic_string<CharT, Traits, Allocator>
1163 to_string( basic_string_view<CharT, Traits> v, Allocator
const & a = Allocator() )
1165 return std::basic_string<CharT,Traits, Allocator>( v.begin(), v.end(), a );
1170 template<
class CharT,
class Traits >
1171 std::basic_string<CharT, Traits>
1174 return std::basic_string<CharT, Traits>( v.begin(), v.end() );
1177 template<
class CharT,
class Traits,
class Allocator >
1178 std::basic_string<CharT, Traits, Allocator>
1179 to_string( basic_string_view<CharT, Traits> v, Allocator
const & a )
1181 return std::basic_string<CharT, Traits, Allocator>( v.begin(), v.end(), a );
1184 #endif // nssv_CPP11_OR_GREATER 1186 template<
class CharT,
class Traits,
class Allocator >
1187 basic_string_view<CharT, Traits>
1190 return basic_string_view<CharT, Traits>( s.data(), s.size() );
1195 #endif // nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1203 using sv_lite::basic_string_view;
1204 using sv_lite::string_view;
1205 using sv_lite::wstring_view;
1207 #if nssv_HAVE_WCHAR16_T 1208 using sv_lite::u16string_view;
1210 #if nssv_HAVE_WCHAR32_T 1211 using sv_lite::u32string_view;
1216 using sv_lite::operator==;
1217 using sv_lite::operator!=;
1218 using sv_lite::operator<;
1219 using sv_lite::operator<=;
1220 using sv_lite::operator>;
1221 using sv_lite::operator>=;
1223 using sv_lite::operator<<;
1225 #if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1237 #if nssv_HAVE_STD_HASH 1239 #include <functional> 1244 struct hash< nonstd::string_view >
1247 std::size_t operator()( nonstd::string_view v )
const nssv_noexcept 1249 return std::hash<std::string>()( std::string( v.data(), v.size() ) );
1254 struct hash< nonstd::wstring_view >
1257 std::size_t operator()( nonstd::wstring_view v )
const nssv_noexcept 1259 return std::hash<std::wstring>()( std::wstring( v.data(), v.size() ) );
1264 struct hash< nonstd::u16string_view >
1267 std::size_t operator()( nonstd::u16string_view v )
const nssv_noexcept 1269 return std::hash<std::u16string>()( std::u16string( v.data(), v.size() ) );
1274 struct hash< nonstd::u32string_view >
1277 std::size_t operator()( nonstd::u32string_view v )
const nssv_noexcept 1279 return std::hash<std::u32string>()( std::u32string( v.data(), v.size() ) );
1285 #endif // nssv_HAVE_STD_HASH 1289 #endif // nssv_HAVE_STD_STRING_VIEW 1290 #endif // NONSTD_SV_LITE_H_INCLUDED optional_constexpr bool operator!=(optional< T > const &x, optional< U > const &y)
const T * data(const std::vector< T, Alloc > &v)
void swap(linb::any &lhs, linb::any &rhs) noexcept
basic_string_view< CharT, Traits > to_string_view(std::basic_string< CharT, Traits, Allocator > const &s)
optional_constexpr bool operator==(optional< T > const &x, optional< U > const &y)
std::ostream & operator<<(std::ostream &os, const BT::NodeStatus &status)
optional_constexpr bool operator<=(optional< T > const &x, optional< U > const &y)
#define nssv_RESTORE_WARNINGS()
optional_constexpr bool operator<(optional< T > const &x, optional< U > const &y)
optional_constexpr bool operator>=(optional< T > const &x, optional< U > const &y)
static volatile int count
#define nssv_DISABLE_MSVC_WARNINGS(codes)
std::basic_string< CharT, Traits, Allocator > to_string(basic_string_view< CharT, Traits > v, Allocator const &a)
std::basic_string< CharT, Traits > to_string(basic_string_view< CharT, Traits > v)
optional_constexpr bool operator>(optional< T > const &x, optional< U > const &y)