From 3fd447ea66fa0594cca27d8a68bf4e628a4b65c7 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Fri, 12 Aug 2022 18:00:41 -0300 Subject: [PATCH] rename emplace functions fix #387 --- README.md | 2 +- include/boost/url/impl/params.hpp | 18 ++++++----- include/boost/url/impl/params_encoded.hpp | 18 ++++++----- include/boost/url/impl/params_encoded.ipp | 2 +- include/boost/url/params.hpp | 20 ++++++++---- include/boost/url/params_encoded.hpp | 24 +++++++++----- test/unit/params.cpp | 38 +++++++++++------------ test/unit/params_encoded.cpp | 38 +++++++++++------------ test/unit/snippets.cpp | 5 ++- 9 files changed, 94 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 445e8bfb..f3bf526a 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ u.set_scheme( "http" ) .set_encoded_path( "/index.htm" ) .remove_query() .remove_fragment() - .params().emplace_back( "key", "value" ); + .params().append( "key", "value" ); std::cout << u; diff --git a/include/boost/url/impl/params.hpp b/include/boost/url/impl/params.hpp index 3d91ecc6..ff0e5aeb 100644 --- a/include/boost/url/impl/params.hpp +++ b/include/boost/url/impl/params.hpp @@ -254,7 +254,11 @@ insert( iterator before, FwdIt first, FwdIt last) -> - iterator + typename std::enable_if< + !std::is_convertible< + FwdIt, string_view + >::value, + iterator>::type { return insert(before, first, last, typename std::iterator_traits< @@ -359,7 +363,7 @@ replace( inline auto params:: -emplace_at( +replace( iterator pos, string_view key, string_view value) -> @@ -389,7 +393,7 @@ emplace_at( inline auto params:: -emplace_at( +replace( iterator pos, string_view key) -> iterator @@ -414,7 +418,7 @@ emplace_at( inline auto params:: -emplace_before( +insert( iterator before, string_view key, string_view value) -> @@ -431,7 +435,7 @@ emplace_before( inline auto params:: -emplace_before( +insert( iterator before, string_view key) -> iterator @@ -458,7 +462,7 @@ erase(iterator pos) -> inline auto params:: -emplace_back( +append( string_view key) -> iterator { @@ -470,7 +474,7 @@ emplace_back( inline auto params:: -emplace_back( +append( string_view key, string_view value) -> iterator diff --git a/include/boost/url/impl/params_encoded.hpp b/include/boost/url/impl/params_encoded.hpp index c10302fd..f5b390ae 100644 --- a/include/boost/url/impl/params_encoded.hpp +++ b/include/boost/url/impl/params_encoded.hpp @@ -272,7 +272,11 @@ insert( iterator before, FwdIt first, FwdIt last) -> - iterator + typename std::enable_if< + !std::is_convertible< + FwdIt, string_view + >::value, + iterator>::type { return insert(before, first, last, typename std::iterator_traits< @@ -377,7 +381,7 @@ replace( inline auto params_encoded:: -emplace_at( +replace( iterator pos, string_view key, string_view value) -> @@ -405,7 +409,7 @@ emplace_at( inline auto params_encoded:: -emplace_back( +append( string_view key) -> iterator { @@ -417,7 +421,7 @@ emplace_back( inline auto params_encoded:: -emplace_back( +append( string_view key, string_view value) -> iterator @@ -430,7 +434,7 @@ emplace_back( inline auto params_encoded:: -emplace_at( +replace( iterator pos, string_view key) -> iterator @@ -459,7 +463,7 @@ emplace_at( inline auto params_encoded:: -emplace_before( +insert( iterator before, string_view key, string_view value) -> @@ -476,7 +480,7 @@ emplace_before( inline auto params_encoded:: -emplace_before( +insert( iterator before, string_view key) -> iterator diff --git a/include/boost/url/impl/params_encoded.ipp b/include/boost/url/impl/params_encoded.ipp index a61ebbbc..1c6f415f 100644 --- a/include/boost/url/impl/params_encoded.ipp +++ b/include/boost/url/impl/params_encoded.ipp @@ -119,7 +119,7 @@ replace_value( string_view value) -> iterator { - return emplace_at( + return replace( pos, (*pos).key, value); diff --git a/include/boost/url/params.hpp b/include/boost/url/params.hpp index 21057b91..6efea77d 100644 --- a/include/boost/url/params.hpp +++ b/include/boost/url/params.hpp @@ -331,7 +331,15 @@ public: */ template +#ifndef BOOST_URL_DOCS + typename std::enable_if< + !std::is_convertible< + FwdIt, string_view + >::value, + iterator>::type +#else iterator +#endif insert( iterator before, FwdIt first, @@ -470,7 +478,7 @@ public: */ iterator - emplace_at( + replace( iterator pos, string_view key, string_view value); @@ -490,7 +498,7 @@ public: */ iterator - emplace_at( + replace( iterator pos, string_view key); @@ -506,7 +514,7 @@ public: */ iterator - emplace_before( + insert( iterator before, string_view key, string_view value); @@ -521,7 +529,7 @@ public: */ iterator - emplace_before( + insert( iterator before, string_view key); @@ -569,7 +577,7 @@ public: */ iterator - emplace_back( + append( string_view key); /** Construct element at the end of the container @@ -582,7 +590,7 @@ public: */ iterator - emplace_back( + append( string_view key, string_view value); diff --git a/include/boost/url/params_encoded.hpp b/include/boost/url/params_encoded.hpp index 70035ed3..40acc94a 100644 --- a/include/boost/url/params_encoded.hpp +++ b/include/boost/url/params_encoded.hpp @@ -386,7 +386,15 @@ public: */ template +#ifndef BOOST_URL_DOCS + typename std::enable_if< + !std::is_convertible< + FwdIt, string_view + >::value, + iterator>::type +#else iterator +#endif insert( iterator before, FwdIt first, @@ -534,7 +542,7 @@ public: */ iterator - emplace_at( + replace( iterator pos, string_view key, string_view value); @@ -555,7 +563,7 @@ public: */ iterator - emplace_at( + replace( iterator pos, string_view key); @@ -571,8 +579,8 @@ public: */ iterator - emplace_before( - iterator before, + insert( + iterator before, // used to be emplace_before string_view key, string_view value); @@ -586,8 +594,8 @@ public: */ iterator - emplace_before( - iterator before, + insert( + iterator before, // used to be emplace_before string_view key); //-------------------------------------------- @@ -638,7 +646,7 @@ public: */ iterator - emplace_back( + append( string_view key); /** Construct element at the last position of the container @@ -651,7 +659,7 @@ public: */ iterator - emplace_back( + append( string_view key, string_view value); diff --git a/test/unit/params.cpp b/test/unit/params.cpp index 1ae31074..4f64a543 100644 --- a/test/unit/params.cpp +++ b/test/unit/params.cpp @@ -229,13 +229,13 @@ public: "/?k0=0&k%31=1&k2=#f"); } - // emplace_at(iterator, string_view, string_view) - // emplace_at(iterator, Key, Value) + // replace(iterator, string_view, string_view) + // replace(iterator, Key, Value) { url u = parse_uri_reference( "/?k0=0&k%31=1&k2=#f").value(); params p = u.params(); - auto it = p.emplace_at( + auto it = p.replace( std::next(p.begin()), "k1", "1"); BOOST_TEST_EQ(it, std::next(p.begin())); @@ -245,13 +245,13 @@ public: "/?k0=0&k1=1&k2=#f"); } - // emplace_at(iterator, string_view) - // emplace_at(iterator, Key) + // replace(iterator, string_view) + // replace(iterator, Key) { url u = parse_uri_reference( "/?k0=0&k1=1&k2=&k3#f").value(); params p = u.params(); - auto it = p.emplace_at( + auto it = p.replace( std::next(p.begin(), 2), "hello_world"); BOOST_TEST_EQ(it, std::next(p.begin(), 2)); @@ -261,13 +261,13 @@ public: "/?k0=0&k1=1&hello_world&k3#f"); } - // emplace_before(iterator, string_view, string_view) - // emplace_before(iterator, Key, Value) + // insert(iterator, string_view, string_view) + // insert(iterator, Key, Value) { url u = parse_uri_reference( "/?k0=0&k2=&k3#f").value(); params p = u.params(); - auto it = p.emplace_before( + auto it = p.insert( std::next(p.begin()), "k1", "1"); BOOST_TEST_EQ(it, std::next(p.begin())); BOOST_TEST(u.encoded_query() == @@ -276,13 +276,13 @@ public: "/?k0=0&k1=1&k2=&k3#f"); } - // emplace_before(iterator, string_view) - // emplace_before(iterator, Key) + // insert(iterator, string_view) + // insert(iterator, Key) { url u = parse_uri_reference( "/?k0=0&k2=&k3#f").value(); params p = u.params(); - auto it = p.emplace_before( + auto it = p.insert( std::next(p.begin()), "k1"); BOOST_TEST_EQ(it, std::next(p.begin())); BOOST_TEST(u.encoded_query() == @@ -334,34 +334,34 @@ public: BOOST_TEST_EQ(p.erase("g"), 0u); } - // emplace_back(Key, Value) - // emplace_back(Key) + // append(Key, Value) + // append(Key) { url u = parse_uri_reference("/#f").value(); params p = u.params(); - p.emplace_back("k0", "0"); + p.append("k0", "0"); BOOST_TEST_EQ(u.encoded_query(), "k0=0"); BOOST_TEST_EQ(u.string(), "/?k0=0#f"); BOOST_TEST_EQ(u.encoded_params().size(), 1u); - p.emplace_back("k1", "1"); + p.append("k1", "1"); BOOST_TEST(u.encoded_query() == "k0=0&k1=1"); BOOST_TEST(u.string() == "/?k0=0&k1=1#f"); BOOST_TEST_EQ(u.encoded_params().size(), 2u); - p.emplace_back("k2", ""); + p.append("k2", ""); BOOST_TEST(u.encoded_query() == "k0=0&k1=1&k2="); BOOST_TEST(u.string() == "/?k0=0&k1=1&k2=#f"); BOOST_TEST_EQ(u.encoded_params().size(), 3u); - p.emplace_back("k3"); + p.append("k3"); BOOST_TEST(u.encoded_query() == "k0=0&k1=1&k2=&k3"); BOOST_TEST(u.string() == "/?k0=0&k1=1&k2=&k3#f"); BOOST_TEST_EQ(u.encoded_params().size(), 4u); - p.emplace_back("", "4444"); + p.append("", "4444"); BOOST_TEST(u.encoded_query() == "k0=0&k1=1&k2=&k3&=4444"); BOOST_TEST(u.string() == diff --git a/test/unit/params_encoded.cpp b/test/unit/params_encoded.cpp index 4235f1cf..2215260e 100644 --- a/test/unit/params_encoded.cpp +++ b/test/unit/params_encoded.cpp @@ -230,13 +230,13 @@ public: "/?k0=0&k%31=1&k2=#f"); } - // emplace_at(iterator, string_view, string_view) - // emplace_at(iterator, Key, Value) + // replace(iterator, string_view, string_view) + // replace(iterator, Key, Value) { url u = parse_uri_reference( "/?k0=0&k%31=1&k2=#f").value(); params_encoded p = u.encoded_params(); - auto it = p.emplace_at( + auto it = p.replace( std::next(p.begin()), "k1", "1"); BOOST_TEST_EQ(it, std::next(p.begin())); @@ -246,13 +246,13 @@ public: "/?k0=0&k1=1&k2=#f"); } - // emplace_at(iterator, string_view) - // emplace_at(iterator, Key) + // replace(iterator, string_view) + // replace(iterator, Key) { url u = parse_uri_reference( "/?k0=0&k1=1&k2=&k3#f").value(); params_encoded p = u.encoded_params(); - auto it = p.emplace_at( + auto it = p.replace( std::next(p.begin(), 2), "hello_world"); BOOST_TEST_EQ(it, std::next(p.begin(), 2)); @@ -262,13 +262,13 @@ public: "/?k0=0&k1=1&hello_world&k3#f"); } - // emplace_before(iterator, string_view, string_view) - // emplace_before(iterator, Key, Value) + // insert(iterator, string_view, string_view) + // insert(iterator, Key, Value) { url u = parse_uri_reference( "/?k0=0&k2=&k3#f").value(); params_encoded p = u.encoded_params(); - auto it = p.emplace_before( + auto it = p.insert( std::next(p.begin()), "k1", "1"); BOOST_TEST_EQ(it, std::next(p.begin())); BOOST_TEST(u.encoded_query() == @@ -277,13 +277,13 @@ public: "/?k0=0&k1=1&k2=&k3#f"); } - // emplace_before(iterator, string_view) - // emplace_before(iterator, Key) + // insert(iterator, string_view) + // insert(iterator, Key) { url u = parse_uri_reference( "/?k0=0&k2=&k3#f").value(); params_encoded p = u.encoded_params(); - auto it = p.emplace_before( + auto it = p.insert( std::next(p.begin()), "k1"); BOOST_TEST_EQ(it, std::next(p.begin())); BOOST_TEST(u.encoded_query() == @@ -335,34 +335,34 @@ public: BOOST_TEST_EQ(p.erase("g"), 0u); } - // emplace_back(Key, Value) - // emplace_back(Key) + // append(Key, Value) + // append(Key) { url u = parse_uri_reference("/#f").value(); params_encoded p = u.encoded_params(); - p.emplace_back("k0", "0"); + p.append("k0", "0"); BOOST_TEST_EQ(u.encoded_query(), "k0=0"); BOOST_TEST_EQ(u.string(), "/?k0=0#f"); BOOST_TEST_EQ(u.encoded_params().size(), 1u); - p.emplace_back("k1", "1"); + p.append("k1", "1"); BOOST_TEST(u.encoded_query() == "k0=0&k1=1"); BOOST_TEST(u.string() == "/?k0=0&k1=1#f"); BOOST_TEST_EQ(u.encoded_params().size(), 2u); - p.emplace_back("k2", ""); + p.append("k2", ""); BOOST_TEST(u.encoded_query() == "k0=0&k1=1&k2="); BOOST_TEST(u.string() == "/?k0=0&k1=1&k2=#f"); BOOST_TEST_EQ(u.encoded_params().size(), 3u); - p.emplace_back("k3"); + p.append("k3"); BOOST_TEST(u.encoded_query() == "k0=0&k1=1&k2=&k3"); BOOST_TEST(u.string() == "/?k0=0&k1=1&k2=&k3#f"); BOOST_TEST_EQ(u.encoded_params().size(), 4u); - p.emplace_back("", "4444"); + p.append("", "4444"); BOOST_TEST(u.encoded_query() == "k0=0&k1=1&k2=&k3&=4444"); BOOST_TEST(u.string() == diff --git a/test/unit/snippets.cpp b/test/unit/snippets.cpp index 612a0078..a0656ee1 100644 --- a/test/unit/snippets.cpp +++ b/test/unit/snippets.cpp @@ -33,8 +33,7 @@ using_url_views() { { //[snippet_accessing_1 - string_view s = "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor"; - url_view u( s ); + url_view u( "https://user:pass@example.com:443/path/to/my%2dfile.txt?id=42&name=John%20Doe+Jingleheimer%2DSchmidt#page%20anchor" ); assert(u.scheme() == "https"); assert(u.authority().string() == "user:pass@example.com:443"); assert(u.userinfo() == "user:pass"); @@ -271,7 +270,7 @@ using_urls() //[snippet_quicklook_modifying_5 params p = u.params(); - p.emplace_at(p.find("name"), "name", "Vinnie Falco"); + p.replace(p.find("name"), "name", "John Doe"); std::cout << u << "\n"; //] }