diff --git a/CHANGELOG.md b/CHANGELOG.md index 54b38159..e3ebacb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 86: * Boost prep +* Remove use of lexical_cast -------------------------------------------------------------------------------- diff --git a/example/websocket-server-async/websocket_server_async.cpp b/example/websocket-server-async/websocket_server_async.cpp index 00ffc491..3aa15a88 100644 --- a/example/websocket-server-async/websocket_server_async.cpp +++ b/example/websocket-server-async/websocket_server_async.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/extras/boost/beast/unit_test/reporter.hpp b/extras/boost/beast/unit_test/reporter.hpp index fef7d878..888895d6 100644 --- a/extras/boost/beast/unit_test/reporter.hpp +++ b/extras/boost/beast/unit_test/reporter.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -218,8 +217,7 @@ reporter<_>::fmtdur(typename clock_type::duration const& d) using namespace std::chrono; auto const ms = duration_cast(d); if(ms < seconds{1}) - return boost::lexical_cast( - ms.count()) + "ms"; + return std::to_string(ms.count()) + "ms"; std::stringstream ss; ss << std::fixed << std::setprecision(1) << (ms.count()/1000.) << "s"; diff --git a/extras/boost/beast/unit_test/suite.hpp b/extras/boost/beast/unit_test/suite.hpp index e9b353dc..65ce12bd 100644 --- a/extras/boost/beast/unit_test/suite.hpp +++ b/extras/boost/beast/unit_test/suite.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -36,7 +35,7 @@ make_reason(String const& reason, namespace fs = boost::filesystem; s.append(fs::path{file}.filename().string()); s.append("("); - s.append(boost::lexical_cast(line)); + s.append(std::to_string(line)); s.append(")"); return s; } diff --git a/test/benchmarks/parser.cpp b/test/benchmarks/parser.cpp index 1071c129..2e28edb6 100644 --- a/test/benchmarks/parser.cpp +++ b/test/benchmarks/parser.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -42,8 +41,14 @@ public: std::string to_string(ConstBufferSequence const& bs) { - return boost::lexical_cast< - std::string>(buffers(bs)); + using boost::asio::buffer_cast; + using boost::asio::buffer_size; + std::string s; + s.reserve(buffer_size(bs)); + for(boost::asio::const_buffer b : bs) + s.append(buffer_cast(b), + buffer_size(b)); + return s; } corpus diff --git a/test/core/buffers_adapter.cpp b/test/core/buffers_adapter.cpp index 3df7794b..fb94b952 100644 --- a/test/core/buffers_adapter.cpp +++ b/test/core/buffers_adapter.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include namespace boost { @@ -30,8 +29,14 @@ public: std::string to_string(ConstBufferSequence const& bs) { - return boost::lexical_cast< - std::string>(buffers(bs)); + using boost::asio::buffer_cast; + using boost::asio::buffer_size; + std::string s; + s.reserve(buffer_size(bs)); + for(boost::asio::const_buffer b : bs) + s.append(buffer_cast(b), + buffer_size(b)); + return s; } void testBuffersAdapter() diff --git a/test/core/flat_buffer.cpp b/test/core/flat_buffer.cpp index 572e0b4a..df88842f 100644 --- a/test/core/flat_buffer.cpp +++ b/test/core/flat_buffer.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include namespace boost { diff --git a/test/core/ostream.cpp b/test/core/ostream.cpp index 67be0992..7a0c4782 100644 --- a/test/core/ostream.cpp +++ b/test/core/ostream.cpp @@ -12,7 +12,6 @@ #include #include -#include #include namespace boost { @@ -21,6 +20,21 @@ namespace beast { class ostream_test : public beast::unit_test::suite { public: + template + static + std::string + to_string(ConstBufferSequence const& bs) + { + using boost::asio::buffer_cast; + using boost::asio::buffer_size; + std::string s; + s.reserve(buffer_size(bs)); + for(boost::asio::const_buffer b : bs) + s.append(buffer_cast(b), + buffer_size(b)); + return s; + } + void run() override { @@ -29,8 +43,7 @@ public: auto os = ostream(b); os << "Hello, world!\n"; os.flush(); - BOOST_BEAST_EXPECT(boost::lexical_cast( - buffers(b.data())) == "Hello, world!\n"); + BOOST_BEAST_EXPECT(to_string(b.data()) == "Hello, world!\n"); auto os2 = std::move(os); } { @@ -45,8 +58,7 @@ public: "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef"; multi_buffer b; ostream(b) << s; - BOOST_BEAST_EXPECT(boost::lexical_cast( - buffers(b.data())) == s); + BOOST_BEAST_EXPECT(to_string(b.data()) == s); } } }; diff --git a/test/http/doc_examples.cpp b/test/http/doc_examples.cpp index 1b6222cc..407629b6 100644 --- a/test/http/doc_examples.cpp +++ b/test/http/doc_examples.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace boost { @@ -43,6 +44,31 @@ public: { } + template + static + std::string + to_string(message const& m) + { + std::stringstream ss; + ss << m; + return ss.str(); + } + + template + static + std::string + to_string(ConstBufferSequence const& bs) + { + using boost::asio::buffer_cast; + using boost::asio::buffer_size; + std::string s; + s.reserve(buffer_size(bs)); + for(boost::asio::const_buffer b : bs) + s.append(buffer_cast(b), + buffer_size(b)); + return s; + } + template bool equal_body(string_view sv, string_view body) @@ -157,8 +183,7 @@ public: response res; read_istream(is, buffer, res, ec); BOOST_BEAST_EXPECTS(! ec, ec.message()); - BOOST_BEAST_EXPECT(boost::lexical_cast< - std::string>(res) == s); + BOOST_BEAST_EXPECT(to_string(res) == s); } void @@ -173,8 +198,7 @@ public: error_code ec; write_ostream(os, req, ec); BOOST_BEAST_EXPECTS(! ec, ec.message()); - BOOST_BEAST_EXPECT(boost::lexical_cast< - std::string>(req) == os.str()); + BOOST_BEAST_EXPECT(to_string(req) == os.str()); } void @@ -343,8 +367,7 @@ public: std::allocator{} ), ec); BOOST_BEAST_EXPECT( - boost::lexical_cast( - buffers(p.server.buffer.data())) == + to_string(p.server.buffer.data()) == "HTTP/1.1 200 OK\r\n" "Server: test\r\n" "Accept: Expires, Content-MD5\r\n" diff --git a/test/http/dynamic_body.cpp b/test/http/dynamic_body.cpp index 4c5b1137..fe0918ad 100644 --- a/test/http/dynamic_body.cpp +++ b/test/http/dynamic_body.cpp @@ -17,7 +17,6 @@ #include #include #include -#include namespace boost { namespace beast { @@ -28,6 +27,31 @@ class dynamic_body_test : public beast::unit_test::suite boost::asio::io_service ios_; public: + template + static + std::string + to_string(message const& m) + { + std::stringstream ss; + ss << m; + return ss.str(); + } + + template + static + std::string + to_string(ConstBufferSequence const& bs) + { + using boost::asio::buffer_cast; + using boost::asio::buffer_size; + std::string s; + s.reserve(buffer_size(bs)); + for(boost::asio::const_buffer b : bs) + s.append(buffer_cast(b), + buffer_size(b)); + return s; + } + void run() override { @@ -42,9 +66,8 @@ public: multi_buffer b; read(ss, b, p); auto const& m = p.get(); - BOOST_BEAST_EXPECT(boost::lexical_cast( - buffers(m.body.data())) == "xyz"); - BOOST_BEAST_EXPECT(boost::lexical_cast(m) == s); + BOOST_BEAST_EXPECT(to_string(m.body.data()) == "xyz"); + BOOST_BEAST_EXPECT(to_string(m) == s); } }; diff --git a/test/http/fields.cpp b/test/http/fields.cpp index 99fbd957..b69955d3 100644 --- a/test/http/fields.cpp +++ b/test/http/fields.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace boost { namespace beast { @@ -37,7 +37,7 @@ public: fill(std::size_t n, basic_fields& f) { for(std::size_t i = 1; i<= n; ++i) - f.insert(boost::lexical_cast(i), i); + f.insert(std::to_string(i), i); } template diff --git a/test/http/write.cpp b/test/http/write.cpp index 0250dd37..af940515 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -258,6 +258,31 @@ public: }; }; + template + static + std::string + to_string(message const& m) + { + std::stringstream ss; + ss << m; + return ss.str(); + } + + template + static + std::string + to_string(ConstBufferSequence const& bs) + { + using boost::asio::buffer_cast; + using boost::asio::buffer_size; + std::string s; + s.reserve(buffer_size(bs)); + for(boost::asio::const_buffer b : bs) + s.append(buffer_cast(b), + buffer_size(b)); + return s; + } + template bool equal_body(string_view sv, string_view body) @@ -574,7 +599,7 @@ public: m.version = 11; m.set(field::user_agent, "test"); m.body = "*"; - BOOST_BEAST_EXPECT(boost::lexical_cast(m) == + BOOST_BEAST_EXPECT(to_string(m) == "GET / HTTP/1.1\r\nUser-Agent: test\r\n\r\n*"); } diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index 2ab8c9ef..6f04028f 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -46,10 +46,17 @@ public: std::string to_string(ConstBufferSequence const& bs) { - return boost::lexical_cast< - std::string>(buffers(bs)); + using boost::asio::buffer_cast; + using boost::asio::buffer_size; + std::string s; + s.reserve(buffer_size(bs)); + for(boost::asio::const_buffer b : bs) + s.append(buffer_cast(b), + buffer_size(b)); + return s; } + struct con { stream ws; diff --git a/test/websocket/websocket_async_echo_server.hpp b/test/websocket/websocket_async_echo_server.hpp index 9c04fa5f..8ee7bd8c 100644 --- a/test/websocket/websocket_async_echo_server.hpp +++ b/test/websocket/websocket_async_echo_server.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -374,8 +373,8 @@ private: if(d.server.log_) if(ec != boost::beast::websocket::error::closed) d.server.fail("[#" + std::to_string(d.id) + - " " + boost::lexical_cast(d.ep) + - "] " + what, ec); + " " + d.ep.address().to_string() + ":" + + std::to_string(d.ep.port()) + "] " + what, ec); } }; diff --git a/test/websocket/websocket_sync_echo_server.hpp b/test/websocket/websocket_sync_echo_server.hpp index d2432381..9e7cd0ff 100644 --- a/test/websocket/websocket_sync_echo_server.hpp +++ b/test/websocket/websocket_sync_echo_server.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -216,8 +215,8 @@ private: if(log_) if(ec != boost::beast::websocket::error::closed) fail("[#" + std::to_string(id) + " " + - boost::lexical_cast(ep) + - "] " + what, ec); + ep.address().to_string() + ":" + + std::to_string(ep.port()) + "] " + what, ec); } void diff --git a/test/wstest/main.cpp b/test/wstest/main.cpp index 0230e263..79e73e5d 100644 --- a/test/wstest/main.cpp +++ b/test/wstest/main.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -148,7 +147,7 @@ private: if(ec) return fail("on_connect", ec); ws_.async_handshake( - boost::lexical_cast(ep_), + ep_.address().to_string() + ":" + std::to_string(ep_.port()), "/", alloc_.wrap(std::bind( &connection::on_handshake,