diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index b899d54..fae3dea 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -145,31 +145,36 @@ struct is_string_like< // directly and other convertible types such as std::string. // When no string_view type is available, then we check for the // data and size member functions, and use them directly for assignments. -template +// Types convertible to basic_static_string are not considered viewable +// to prevent any ambiguity during overload resolution. +template struct enable_if_viewable { }; -template -struct enable_if_viewable +struct enable_if_viewable::value + is_string_like::value && + !std::is_convertible&>::value #elif defined(BOOST_STATIC_STRING_STANDALONE) std::is_convertible>::value && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible&>::value #else ( std::is_convertible>::value || std::is_convertible>::value ) && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible&>::value #endif >::type> { using type = void; }; -template -using enable_if_viewable_t = typename enable_if_viewable::type; +template +using enable_if_viewable_t = typename enable_if_viewable::type; // The common string_view type used in private operations with enable_if_viewable_t // - T const& itself when no string_view type is available @@ -1117,7 +1122,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > explicit @@ -1137,7 +1142,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -1314,7 +1319,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible::value @endcode @return `*this` @@ -1325,7 +1331,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -1603,7 +1609,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible::value @endcode @return `*this` @@ -1614,7 +1621,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -1648,7 +1655,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible::value @endcode @return `*this` @@ -1664,7 +1672,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > basic_static_string& @@ -2594,7 +2602,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @param index The index to insert at. @param t The string to insert from. @@ -2604,7 +2613,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -2635,7 +2644,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return `*this` @@ -2651,7 +2661,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3006,7 +3016,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible::value @endcode @return `*this` @@ -3017,7 +3028,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3043,7 +3054,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible::value @endcode @return `*this` @@ -3059,7 +3071,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3181,7 +3193,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value + !std::is_convertible::value && + !std::is_convertible::value @endcode @return `*this` @@ -3192,7 +3205,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3440,7 +3453,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value. + !std::is_convertible::value && + !std::is_convertible::value. @endcode @return The result of lexicographically comparing `s` and the string. @@ -3449,7 +3463,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3484,7 +3498,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value. + !std::is_convertible::value && + !std::is_convertible::value. @endcode @return The result of lexicographically comparing `s` and `sub`. @@ -3497,7 +3512,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3535,7 +3550,8 @@ public: @code std::is_convertible::value && - !std::is_convertible::value. + !std::is_convertible::value && + !std::is_convertible::value. @endcode @return The result of lexicographically comparing `sub1` and `sub2`. @@ -3552,7 +3568,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3867,7 +3883,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return `*this` @@ -3880,7 +3897,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -3913,7 +3930,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return `*this` @@ -3930,7 +3948,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -4129,7 +4147,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return `*this` @@ -4142,7 +4161,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -4392,7 +4411,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return The lowest index `idx` greater than or equal to `pos` where each element of `{sv.begin(), sv.end())` is equal to @@ -4405,7 +4425,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -4549,7 +4569,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return The highest index `idx` less than or equal to `pos` where each element of `{sv.begin(), sv.end())` is equal to @@ -4562,7 +4583,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -4702,7 +4723,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return The index corrosponding to the first occurrence of any of the characters in `{sv.begin(), sv.end())` within @@ -4714,7 +4736,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -4849,7 +4871,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return The index corrosponding to the last occurrence of any of the characters in `{sv.begin(), sv.end())` within @@ -4861,7 +4884,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -4995,7 +5018,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return The index corrosponding to the first occurrence of a character that is not in `{sv.begin(), sv.end())` within @@ -5007,7 +5031,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5140,7 +5164,8 @@ public: @par Constraints `std::is_convertible::value && - !std::is_convertible::value`. + !std::is_convertible::value && + !std::is_convertible::value`. @return The index corrosponding to the last occurrence of a character that is not in `{sv.begin(), sv.end())` within @@ -5152,7 +5177,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5284,7 +5309,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5348,7 +5373,7 @@ public: */ template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5617,7 +5642,7 @@ operator==( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5635,7 +5660,7 @@ operator==( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5679,7 +5704,7 @@ operator!=( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5697,7 +5722,7 @@ operator!=( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5741,7 +5766,7 @@ operator<( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5759,7 +5784,7 @@ operator<( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5803,7 +5828,7 @@ operator<=( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5821,7 +5846,7 @@ operator<=( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5865,7 +5890,7 @@ operator>( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5883,7 +5908,7 @@ operator>( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5928,7 +5953,7 @@ operator>=( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR @@ -5946,7 +5971,7 @@ operator>=( template + , typename = detail::enable_if_viewable_t #endif > BOOST_STATIC_STRING_CPP14_CONSTEXPR diff --git a/test/static_string.cpp b/test/static_string.cpp index c818975..4a6ee99 100644 --- a/test/static_string.cpp +++ b/test/static_string.cpp @@ -7393,6 +7393,15 @@ testOperatorPlus() } } +// issue 47 +struct issue_47 : static_string<32> +{ + bool compare(const issue_47& other) const + { + return *this < other; + } +}; + int runTests() {