From b6e04c8eced7019b094b33fed6b05b9f55528c7d Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 11 Sep 2022 16:31:33 -0700 Subject: [PATCH] segments mandates use static_assert fix #521 --- .../boost/url/impl/segments_encoded_ref.hpp | 69 ++++++++++++------- include/boost/url/impl/segments_ref.hpp | 63 +++++++++++------ include/boost/url/segments_encoded_ref.hpp | 27 +------- include/boost/url/segments_ref.hpp | 26 ------- 4 files changed, 89 insertions(+), 96 deletions(-) diff --git a/include/boost/url/impl/segments_encoded_ref.hpp b/include/boost/url/impl/segments_encoded_ref.hpp index ede4f483..134672dc 100644 --- a/include/boost/url/impl/segments_encoded_ref.hpp +++ b/include/boost/url/impl/segments_encoded_ref.hpp @@ -13,10 +13,8 @@ #include #include -#include -#include #include -#include +#include namespace boost { namespace urls { @@ -36,15 +34,23 @@ clear() noexcept } template -auto +void segments_encoded_ref:: -assign(FwdIt first, FwdIt last) -> - typename std::enable_if< - std::is_convertible::reference, - pct_string_view>::value>::type +assign( + FwdIt first, FwdIt last) { +/* If you get a compile error here, it + means that the iterators you passed + do not meet the requirements stated + in the documentation. +*/ + static_assert( + std::is_convertible< + typename std::iterator_traits< + FwdIt>::reference, + string_view>::value, + "Type requirements not met"); + u_->edit_segments( begin().it_, end().it_, @@ -59,14 +65,24 @@ insert( iterator before, FwdIt first, FwdIt last) -> - typename std::enable_if< - std::is_convertible::reference, - pct_string_view>::value, - iterator>::type + iterator { - return insert(before, first, last, +/* If you get a compile error here, it + means that the iterators you passed + do not meet the requirements stated + in the documentation. +*/ + static_assert( + std::is_convertible< + typename std::iterator_traits< + FwdIt>::reference, + string_view>::value, + "Type requirements not met"); + + return insert( + before, + first, + last, typename std::iterator_traits< FwdIt>::iterator_category{}); } @@ -89,13 +105,20 @@ replace( iterator to, FwdIt first, FwdIt last) -> - typename std::enable_if< - std::is_convertible::reference, - pct_string_view>::value, - iterator>::type + iterator { +/* If you get a compile error here, it + means that the iterators you passed + do not meet the requirements stated + in the documentation. +*/ + static_assert( + std::is_convertible< + typename std::iterator_traits< + FwdIt>::reference, + string_view>::value, + "Type requirements not met"); + return u_->edit_segments( from.it_, to.it_, diff --git a/include/boost/url/impl/segments_ref.hpp b/include/boost/url/impl/segments_ref.hpp index 33f543df..d2e5c00e 100644 --- a/include/boost/url/impl/segments_ref.hpp +++ b/include/boost/url/impl/segments_ref.hpp @@ -12,9 +12,9 @@ #define BOOST_URL_IMPL_SEGMENTS_REF_HPP #include -#include #include -#include +#include +#include namespace boost { namespace urls { @@ -34,15 +34,22 @@ clear() noexcept } template -auto +void segments_ref:: -assign(FwdIt first, FwdIt last) -> - typename std::enable_if< - std::is_convertible::reference, - string_view>::value>::type +assign(FwdIt first, FwdIt last) { +/* If you get a compile error here, it + means that the iterators you passed + do not meet the requirements stated + in the documentation. +*/ + static_assert( + std::is_convertible< + typename std::iterator_traits< + FwdIt>::reference, + string_view>::value, + "Type requirements not met"); + u_->edit_segments( begin().it_, end().it_, @@ -57,13 +64,20 @@ insert( iterator before, FwdIt first, FwdIt last) -> - typename std::enable_if< - std::is_convertible::reference, - string_view>::value, - iterator>::type + iterator { +/* If you get a compile error here, it + means that the iterators you passed + do not meet the requirements stated + in the documentation. +*/ + static_assert( + std::is_convertible< + typename std::iterator_traits< + FwdIt>::reference, + string_view>::value, + "Type requirements not met"); + return insert( before, first, @@ -90,13 +104,20 @@ replace( iterator to, FwdIt first, FwdIt last) -> - typename std::enable_if< - std::is_convertible::reference, - string_view>::value, - iterator>::type + iterator { +/* If you get a compile error here, it + means that the iterators you passed + do not meet the requirements stated + in the documentation. +*/ + static_assert( + std::is_convertible< + typename std::iterator_traits< + FwdIt>::reference, + string_view>::value, + "Type requirements not met"); + return u_->edit_segments( from.it_, to.it_, diff --git a/include/boost/url/segments_encoded_ref.hpp b/include/boost/url/segments_encoded_ref.hpp index 7aed85e6..36febcc0 100644 --- a/include/boost/url/segments_encoded_ref.hpp +++ b/include/boost/url/segments_encoded_ref.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace boost { namespace urls { @@ -358,15 +359,7 @@ public: to assign. */ template -#ifdef BOOST_URL_DOCS void -#else - typename std::enable_if< - std::is_convertible::reference, - pct_string_view>::value>::type -#endif assign(FwdIt first, FwdIt last); //-------------------------------------------- @@ -509,16 +502,7 @@ public: to insert. */ template -#ifdef BOOST_URL_DOCS iterator -#else - typename std::enable_if< - std::is_convertible::reference, - pct_string_view>::value, - iterator>::type -#endif insert( iterator before, FwdIt first, @@ -729,16 +713,7 @@ public: @param first, last The range of segments to assign. */ template -#ifdef BOOST_URL_DOCS iterator -#else - typename std::enable_if< - std::is_convertible::reference, - pct_string_view>::value, - iterator>::type -#endif replace( iterator from, iterator to, diff --git a/include/boost/url/segments_ref.hpp b/include/boost/url/segments_ref.hpp index 49e376df..dbcd6255 100644 --- a/include/boost/url/segments_ref.hpp +++ b/include/boost/url/segments_ref.hpp @@ -344,15 +344,7 @@ public: to assign. */ template -#ifdef BOOST_URL_DOCS void -#else - typename std::enable_if< - std::is_convertible::reference, - string_view>::value>::type -#endif assign(FwdIt first, FwdIt last); //-------------------------------------------- @@ -479,16 +471,7 @@ public: to insert. */ template -#ifdef BOOST_URL_DOCS iterator -#else - typename std::enable_if< - std::is_convertible::reference, - string_view>::value, - iterator>::type -#endif insert( iterator before, FwdIt first, @@ -682,16 +665,7 @@ public: @param first, last The range of segments to assign. */ template -#ifdef BOOST_URL_DOCS iterator -#else - typename std::enable_if< - std::is_convertible::reference, - string_view>::value, - iterator>::type -#endif replace( iterator from, iterator to,