From 66b93e4006da085ca08cfa6d060bce9efe04fd5e Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sun, 20 Aug 2023 08:27:06 -0500 Subject: [PATCH] Fix string view compat for VS 2013. --- src/engine/strview.h | 263 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) diff --git a/src/engine/strview.h b/src/engine/strview.h index ac8b3fe7c3..6ea94f125a 100644 --- a/src/engine/strview.h +++ b/src/engine/strview.h @@ -26,10 +26,21 @@ #include #include +// RFRM: -begin- Hardwire C++11 #define BOOST_CXX14_CONSTEXPR #define BOOST_NOEXCEPT +#if (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190024210) +#define BOOST_NO_CXX11_CONSTEXPR +#endif +#if defined(BOOST_NO_CXX11_CONSTEXPR) +#define BOOST_CONSTEXPR +#else #define BOOST_CONSTEXPR constexpr +#endif #define BOOST_STATIC_CONSTEXPR static const +#define BOOST_NO_CXX17_HDR_STRING_VIEW +#define BOOST_NO_CXX20_HDR_CONCEPTS +// RFRM: -end- Hardwire C++11 namespace boost { @@ -379,8 +390,30 @@ template class basic_string_view { } +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) + + basic_string_view( std::basic_string_view > const& str ) BOOST_NOEXCEPT: p_( str.data() ), n_( str.size() ) + { + } + +#endif + +#if !defined(BOOST_NO_CXX11_NULLPTR) +# if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) + basic_string_view( std::nullptr_t ) = delete; +# else + +private: + + basic_string_view( std::nullptr_t ); + +public: + +# endif +#endif + // BOOST_CONSTEXPR basic_string_view& operator=( basic_string_view const& ) BOOST_NOEXCEPT & = default; // conversions @@ -390,6 +423,16 @@ template class basic_string_view return std::basic_string, A>( data(), size() ); } +#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) + + template >::type> + operator std::basic_string_view() const BOOST_NOEXCEPT + { + return std::basic_string_view( data(), size() ); + } + +#endif + // iterator support BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT @@ -937,6 +980,195 @@ template class basic_string_view } #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) + + // "sufficient number of additional overloads" + + // against std::string_view + + BOOST_CXX14_CONSTEXPR friend bool operator==( basic_string_view sv1, std::basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.size() == sv2.size() && traits_type::compare( sv1.data(), sv2.data(), sv1.size() ) == 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator==( std::basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.size() == sv2.size() && traits_type::compare( sv1.data(), sv2.data(), sv1.size() ) == 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator!=( basic_string_view sv1, std::basic_string_view sv2 ) BOOST_NOEXCEPT + { + return !( sv1 == sv2 ); + } + + BOOST_CXX14_CONSTEXPR friend bool operator!=( std::basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return !( sv1 == sv2 ); + } + + BOOST_CXX14_CONSTEXPR friend bool operator<( basic_string_view sv1, std::basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) < 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator<( std::basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) < 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator<=( basic_string_view sv1, std::basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) <= 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator<=( std::basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) <= 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>( basic_string_view sv1, std::basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) > 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>( std::basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) > 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>=( basic_string_view sv1, std::basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) >= 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>=( std::basic_string_view sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) >= 0; + } + + // against Ch const* + + BOOST_CXX14_CONSTEXPR friend bool operator==( basic_string_view sv1, Ch const* sv2 ) BOOST_NOEXCEPT + { + return sv1 == basic_string_view( sv2 ); + } + + BOOST_CXX14_CONSTEXPR friend bool operator==( Ch const* sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return basic_string_view( sv1 ) == sv2; + } + + BOOST_CXX14_CONSTEXPR friend bool operator!=( basic_string_view sv1, Ch const* sv2 ) BOOST_NOEXCEPT + { + return !( sv1 == sv2 ); + } + + BOOST_CXX14_CONSTEXPR friend bool operator!=( Ch const* sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return !( sv1 == sv2 ); + } + + BOOST_CXX14_CONSTEXPR friend bool operator<( basic_string_view sv1, Ch const* sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) < 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator<( Ch const* sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) > 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator<=( basic_string_view sv1, Ch const* sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) <= 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator<=( Ch const* sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) >= 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>( basic_string_view sv1, Ch const* sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) > 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>( Ch const* sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) < 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>=( basic_string_view sv1, Ch const* sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) >= 0; + } + + BOOST_CXX14_CONSTEXPR friend bool operator>=( Ch const* sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) <= 0; + } + + // against std::string + + template BOOST_CXX14_CONSTEXPR friend bool operator==( basic_string_view sv1, std::basic_string, A> const& sv2 ) BOOST_NOEXCEPT + { + return sv1.size() == sv2.size() && traits_type::compare( sv1.data(), sv2.data(), sv1.size() ) == 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator==( std::basic_string, A> const& sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv1.size() == sv2.size() && traits_type::compare( sv1.data(), sv2.data(), sv1.size() ) == 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator!=( basic_string_view sv1, std::basic_string, A> const& sv2 ) BOOST_NOEXCEPT + { + return !( sv1 == sv2 ); + } + + template BOOST_CXX14_CONSTEXPR friend bool operator!=( std::basic_string, A> const& sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return !( sv1 == sv2 ); + } + + template BOOST_CXX14_CONSTEXPR friend bool operator<( basic_string_view sv1, std::basic_string, A> const& sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) < 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator<( std::basic_string, A> const& sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) > 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator<=( basic_string_view sv1, std::basic_string, A> const& sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) <= 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator<=( std::basic_string, A> const& sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) >= 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator>( basic_string_view sv1, std::basic_string, A> const& sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) > 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator>( std::basic_string, A> const& sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) < 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator>=( basic_string_view sv1, std::basic_string, A> const& sv2 ) BOOST_NOEXCEPT + { + return sv1.compare( sv2 ) >= 0; + } + + template BOOST_CXX14_CONSTEXPR friend bool operator>=( std::basic_string, A> const& sv1, basic_string_view sv2 ) BOOST_NOEXCEPT + { + return sv2.compare( sv1 ) <= 0; + } + #endif }; @@ -980,8 +1212,14 @@ template BOOST_CONSTEXPR_OR_CONST std::size_t basic_string_view::n typedef basic_string_view string_view; typedef basic_string_view wstring_view; + +#if !defined(BOOST_NO_CXX11_CHAR16_T) typedef basic_string_view u16string_view; +#endif + +#if !defined(BOOST_NO_CXX11_CHAR32_T) typedef basic_string_view u32string_view; +#endif #if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L typedef basic_string_view u8string_view; @@ -990,6 +1228,31 @@ typedef basic_string_view u8string_view; } // namespace core } // namespace boost +// std::common_reference support +// needed for iterators that have reference=string_view and value_type=std::string + +#if !defined(BOOST_NO_CXX20_HDR_CONCEPTS) + +template class Q1, template class Q2> +struct std::basic_common_reference< + boost::core::basic_string_view, + std::basic_string, A>, + Q1, Q2> +{ + using type = boost::core::basic_string_view; +}; + +template class Q1, template class Q2> +struct std::basic_common_reference< + std::basic_string, A>, + boost::core::basic_string_view, + Q1, Q2> +{ + using type = boost::core::basic_string_view; +}; + +#endif + namespace b2 { using string_view = boost::core::string_view;