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
718 ? find_last_of( v, size() - 1 )
719 : to_pos( std::find_first_of( const_reverse_iterator( cbegin() + pos + 1 ), crend(), v.cbegin(), v.cend(), Traits::eq ) );
722 nssv_constexpr size_type find_last_of( CharT c, size_type pos = npos )
const nssv_noexcept
724 return find_last_of( basic_string_view( &c, 1 ), pos );
727 nssv_constexpr size_type find_last_of( CharT
const * s, size_type pos, size_type count )
const 729 return find_last_of( basic_string_view( s, count ), pos );
732 nssv_constexpr size_type find_last_of( CharT
const * s, size_type pos = npos )
const 734 return find_last_of( basic_string_view( s ), pos );
739 nssv_constexpr size_type find_first_not_of( basic_string_view v, size_type pos = 0 )
const nssv_noexcept
743 : to_pos( std::find_if( cbegin() + pos, cend(), not_in_view( v ) ) );
746 nssv_constexpr size_type find_first_not_of( CharT c, size_type pos = 0 )
const nssv_noexcept
748 return find_first_not_of( basic_string_view( &c, 1 ), pos );
751 nssv_constexpr size_type find_first_not_of( CharT
const * s, size_type pos, size_type count )
const 753 return find_first_not_of( basic_string_view( s, count ), pos );
756 nssv_constexpr size_type find_first_not_of( CharT
const * s, size_type pos = 0 )
const 758 return find_first_not_of( basic_string_view( s ), pos );
763 nssv_constexpr size_type find_last_not_of( basic_string_view v, size_type pos = npos )
const nssv_noexcept
768 ? find_last_not_of( v, size() - 1 )
769 : to_pos( std::find_if( const_reverse_iterator( cbegin() + pos + 1 ), crend(), not_in_view( v ) ) );
772 nssv_constexpr size_type find_last_not_of( CharT c, size_type pos = npos )
const nssv_noexcept
774 return find_last_not_of( basic_string_view( &c, 1 ), pos );
777 nssv_constexpr size_type find_last_not_of( CharT
const * s, size_type pos, size_type count )
const 779 return find_last_not_of( basic_string_view( s, count ), pos );
782 nssv_constexpr size_type find_last_not_of( CharT
const * s, size_type pos = npos )
const 784 return find_last_not_of( basic_string_view( s ), pos );
789 #if nssv_CPP17_OR_GREATER 791 #elif nssv_CPP11_OR_GREATER 792 enum : size_type { npos = size_type(-1) };
794 enum { npos = size_type(-1) };
800 const basic_string_view v;
806 return npos == v.find_first_of( c );
812 return it == cend() ? npos : size_type( it - cbegin() );
815 nssv_constexpr size_type to_pos( const_reverse_iterator it )
const 817 return it == crend() ? npos : size_type( crend() - it - 1 );
822 #if nssv_BETWEEN( nssv_COMPILER_GNUC_VERSION, 1, 500 ) 825 return assert( pos < size() ), data_[pos];
834 #if nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS 836 template<
class Allocator >
837 basic_string_view( std::basic_string<CharT, Traits, Allocator>
const & s ) nssv_noexcept
842 #if nssv_HAVE_EXPLICIT_CONVERSION 844 template<
class Allocator >
845 explicit operator std::basic_string<CharT, Traits, Allocator>()
const 850 #endif // nssv_HAVE_EXPLICIT_CONVERSION 852 #if nssv_CPP11_OR_GREATER 854 template<
class Allocator = std::allocator<CharT> >
855 std::basic_string<CharT, Traits, Allocator>
856 to_string( Allocator
const & a = Allocator() )
const 858 return std::basic_string<CharT, Traits, Allocator>( begin(), end(), a );
863 std::basic_string<CharT, Traits>
866 return std::basic_string<CharT, Traits>( begin(), end() );
869 template<
class Allocator >
870 std::basic_string<CharT, Traits, Allocator>
873 return std::basic_string<CharT, Traits, Allocator>( begin(), end(), a );
876 #endif // nssv_CPP11_OR_GREATER 878 #endif // nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS 888 template<
class CharT,
class Traits >
890 basic_string_view <CharT, Traits> lhs,
892 {
return lhs.compare( rhs ) == 0 ; }
894 template<
class CharT,
class Traits >
896 basic_string_view <CharT, Traits> lhs,
898 {
return lhs.compare( rhs ) != 0 ; }
900 template<
class CharT,
class Traits >
902 basic_string_view <CharT, Traits> lhs,
904 {
return lhs.compare( rhs ) < 0 ; }
906 template<
class CharT,
class Traits >
908 basic_string_view <CharT, Traits> lhs,
910 {
return lhs.compare( rhs ) <= 0 ; }
912 template<
class CharT,
class Traits >
914 basic_string_view <CharT, Traits> lhs,
916 {
return lhs.compare( rhs ) > 0 ; }
918 template<
class CharT,
class Traits >
920 basic_string_view <CharT, Traits> lhs,
922 {
return lhs.compare( rhs ) >= 0 ; }
929 #if nssv_CPP11_OR_GREATER && ! nssv_BETWEEN( nssv_COMPILER_MSVC_VERSION, 100, 141 ) 931 #define nssv_BASIC_STRING_VIEW_I(T,U) typename std::decay< basic_string_view<T,U> >::type 933 #if nssv_BETWEEN( nssv_COMPILER_MSVC_VERSION, 140, 150 ) 934 # define nssv_MSVC_ORDER(x) , int=x 936 # define nssv_MSVC_ORDER(x) 941 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
943 basic_string_view <CharT, Traits> lhs,
945 {
return lhs.compare( rhs ) == 0; }
947 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
949 nssv_BASIC_STRING_VIEW_I(CharT, Traits) lhs,
951 {
return lhs.size() == rhs.size() && lhs.compare( rhs ) == 0; }
955 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
957 basic_string_view < CharT, Traits > lhs,
958 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 959 {
return lhs.size() != rhs.size() || lhs.compare( rhs ) != 0 ; }
961 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
963 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
965 {
return lhs.compare( rhs ) != 0 ; }
969 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
971 basic_string_view < CharT, Traits > lhs,
972 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 973 {
return lhs.compare( rhs ) < 0 ; }
975 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
977 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
979 {
return lhs.compare( rhs ) < 0 ; }
983 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
985 basic_string_view < CharT, Traits > lhs,
986 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 987 {
return lhs.compare( rhs ) <= 0 ; }
989 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
991 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
993 {
return lhs.compare( rhs ) <= 0 ; }
997 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
999 basic_string_view < CharT, Traits > lhs,
1000 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 1001 {
return lhs.compare( rhs ) > 0 ; }
1003 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
1005 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
1007 {
return lhs.compare( rhs ) > 0 ; }
1011 template<
class CharT,
class Traits nssv_MSVC_ORDER(1) >
1013 basic_string_view < CharT, Traits > lhs,
1014 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs )
nssv_noexcept 1015 {
return lhs.compare( rhs ) >= 0 ; }
1017 template<
class CharT,
class Traits nssv_MSVC_ORDER(2) >
1019 nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs,
1021 {
return lhs.compare( rhs ) >= 0 ; }
1023 #undef nssv_MSVC_ORDER 1024 #undef nssv_BASIC_STRING_VIEW_I 1026 #endif // nssv_CPP11_OR_GREATER 1032 template<
class Stream >
1033 void write_padding( Stream & os, std::streamsize n )
1035 for ( std::streamsize i = 0; i < n; ++i )
1036 os.rdbuf()->sputc( os.fill() );
1039 template<
class Stream,
class View >
1040 Stream & write_to_stream( Stream & os, View
const & sv )
1042 typename Stream::sentry sentry( os );
1047 const std::streamsize length =
static_cast<std::streamsize
>( sv.length() );
1050 const bool pad = ( length < os.width() );
1051 const bool left_pad = pad && ( os.flags() & std::ios_base::adjustfield ) == std::ios_base::right;
1054 write_padding( os, os.width() - length );
1057 os.rdbuf()->sputn( sv.begin(), length );
1059 if ( pad && !left_pad )
1060 write_padding( os, os.width() - length );
1070 template<
class CharT,
class Traits >
1071 std::basic_ostream<CharT, Traits> &
1073 std::basic_ostream<CharT, Traits>& os,
1074 basic_string_view <CharT, Traits> sv )
1076 return detail::write_to_stream( os, sv );
1081 typedef basic_string_view<char> string_view;
1082 typedef basic_string_view<wchar_t> wstring_view;
1083 #if nssv_HAVE_WCHAR16_T 1084 typedef basic_string_view<char16_t> u16string_view;
1085 typedef basic_string_view<char32_t> u32string_view;
1094 #if nssv_HAVE_USER_DEFINED_LITERALS 1100 #if nssv_CONFIG_STD_SV_OPERATOR && nssv_HAVE_STD_DEFINED_LITERALS 1104 return nonstd::sv_lite::string_view{
str, len };
1109 return nonstd::sv_lite::u16string_view{
str, len };
1114 return nonstd::sv_lite::u32string_view{
str, len };
1119 return nonstd::sv_lite::wstring_view{
str, len };
1122 #endif // nssv_CONFIG_STD_SV_OPERATOR && nssv_HAVE_STD_DEFINED_LITERALS 1124 #if nssv_CONFIG_USR_SV_OPERATOR 1128 return nonstd::sv_lite::string_view{
str, len };
1133 return nonstd::sv_lite::u16string_view{
str, len };
1138 return nonstd::sv_lite::u32string_view{
str, len };
1143 return nonstd::sv_lite::wstring_view{
str, len };
1146 #endif // nssv_CONFIG_USR_SV_OPERATOR 1156 #if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1163 #if nssv_CPP11_OR_GREATER && nssv_COMPILER_MSVC_VERSION != 140 1165 template<
class CharT,
class Traits,
class Allocator = std::allocator<CharT> >
1166 std::basic_string<CharT, Traits, Allocator>
1167 to_string( basic_string_view<CharT, Traits> v, Allocator
const & a = Allocator() )
1169 return std::basic_string<CharT,Traits, Allocator>( v.begin(), v.end(), a );
1174 template<
class CharT,
class Traits >
1175 std::basic_string<CharT, Traits>
1178 return std::basic_string<CharT, Traits>( v.begin(), v.end() );
1181 template<
class CharT,
class Traits,
class Allocator >
1182 std::basic_string<CharT, Traits, Allocator>
1183 to_string( basic_string_view<CharT, Traits> v, Allocator
const & a )
1185 return std::basic_string<CharT, Traits, Allocator>( v.begin(), v.end(), a );
1188 #endif // nssv_CPP11_OR_GREATER 1190 template<
class CharT,
class Traits,
class Allocator >
1191 basic_string_view<CharT, Traits>
1194 return basic_string_view<CharT, Traits>( s.data(), s.size() );
1199 #endif // nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1207 using sv_lite::basic_string_view;
1208 using sv_lite::string_view;
1209 using sv_lite::wstring_view;
1211 #if nssv_HAVE_WCHAR16_T 1212 using sv_lite::u16string_view;
1214 #if nssv_HAVE_WCHAR32_T 1215 using sv_lite::u32string_view;
1220 using sv_lite::operator==;
1221 using sv_lite::operator!=;
1222 using sv_lite::operator<;
1223 using sv_lite::operator<=;
1224 using sv_lite::operator>;
1225 using sv_lite::operator>=;
1227 using sv_lite::operator<<;
1229 #if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1241 #if nssv_HAVE_STD_HASH 1243 #include <functional> 1248 struct hash< nonstd::string_view >
1251 std::size_t operator()( nonstd::string_view v )
const nssv_noexcept 1253 return std::hash<std::string>()( std::string( v.data(), v.size() ) );
1258 struct hash< nonstd::wstring_view >
1261 std::size_t operator()( nonstd::wstring_view v )
const nssv_noexcept 1263 return std::hash<std::wstring>()( std::wstring( v.data(), v.size() ) );
1268 struct hash< nonstd::u16string_view >
1271 std::size_t operator()( nonstd::u16string_view v )
const nssv_noexcept 1273 return std::hash<std::u16string>()( std::u16string( v.data(), v.size() ) );
1278 struct hash< nonstd::u32string_view >
1281 std::size_t operator()( nonstd::u32string_view v )
const nssv_noexcept 1283 return std::hash<std::u32string>()( std::u32string( v.data(), v.size() ) );
1289 #endif // nssv_HAVE_STD_HASH 1293 #endif // nssv_HAVE_STD_STRING_VIEW 1294 #endif // NONSTD_SV_LITE_H_INCLUDED
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)
std::ostream & operator<<(std::ostream &os, const BT::NodeStatus &status)
#define nssv_RESTORE_WARNINGS()
const T * data(const std::vector< T, Alloc > &v)
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)