Use boost::lexical_cast instead of std::to_string

fix #176
This commit is contained in:
Vinnie Falco
2016-11-09 10:40:09 -05:00
parent 2a50915322
commit aa8e7432c2
10 changed files with 24 additions and 13 deletions

View File

@ -2,6 +2,7 @@
* Boost library min/max guidance * Boost library min/max guidance
* Improvements to code coverage * Improvements to code coverage
* Use boost::lexical_cast instead of std::to_string
HTTP HTTP

View File

@ -10,6 +10,7 @@
#include <beast/core/streambuf.hpp> #include <beast/core/streambuf.hpp>
#include <beast/http.hpp> #include <beast/http.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream> #include <iostream>
using namespace beast::http; using namespace beast::http;
@ -39,8 +40,8 @@ int main(int, char const*[])
req.method = "GET"; req.method = "GET";
req.url = "/"; req.url = "/";
req.version = 11; req.version = 11;
req.headers.insert("Host", host + req.headers.insert("Host", host + std::string(":") +
std::string(":") + std::to_string(ep.port())); boost::lexical_cast<std::string>(ep.port()));
req.headers.insert("User-Agent", "beast/http"); req.headers.insert("User-Agent", "beast/http");
prepare(req); prepare(req);
write(sock, req); write(sock, req);

View File

@ -7,6 +7,7 @@
#include <beast/http.hpp> #include <beast/http.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -25,7 +26,8 @@ int main()
req.method = "GET"; req.method = "GET";
req.url = "/"; req.url = "/";
req.version = 11; req.version = 11;
req.headers.replace("Host", host + ":" + std::to_string(sock.remote_endpoint().port())); req.headers.replace("Host", host + ":" +
boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
req.headers.replace("User-Agent", "Beast"); req.headers.replace("User-Agent", "Beast");
beast::http::prepare(req); beast::http::prepare(req);
beast::http::write(sock, req); beast::http::write(sock, req);

View File

@ -8,6 +8,7 @@
#include <beast/http.hpp> #include <beast/http.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/asio/ssl.hpp> #include <boost/asio/ssl.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -38,7 +39,7 @@ int main()
req.url = "/"; req.url = "/";
req.version = 11; req.version = 11;
req.headers.insert("Host", host + ":" + req.headers.insert("Host", host + ":" +
std::to_string(sock.remote_endpoint().port())); boost::lexical_cast<std::string>(sock.remote_endpoint().port()));
req.headers.insert("User-Agent", "Beast"); req.headers.insert("User-Agent", "Beast");
beast::http::prepare(req); beast::http::prepare(req);
beast::http::write(stream, req); beast::http::write(stream, req);

View File

@ -10,6 +10,7 @@
#include <beast/unit_test/amount.hpp> #include <beast/unit_test/amount.hpp>
#include <beast/unit_test/recorder.hpp> #include <beast/unit_test/recorder.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>
@ -214,7 +215,8 @@ reporter<_>::fmtdur(typename clock_type::duration const& d)
using namespace std::chrono; using namespace std::chrono;
auto const ms = duration_cast<milliseconds>(d); auto const ms = duration_cast<milliseconds>(d);
if(ms < seconds{1}) if(ms < seconds{1})
return std::to_string(ms.count()) + "ms"; return boost::lexical_cast<std::string>(
ms.count()) + "ms";
std::stringstream ss; std::stringstream ss;
ss << std::fixed << std::setprecision(1) << ss << std::fixed << std::setprecision(1) <<
(ms.count()/1000.) << "s"; (ms.count()/1000.) << "s";

View File

@ -10,6 +10,7 @@
#include <beast/unit_test/runner.hpp> #include <beast/unit_test/runner.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -31,7 +32,7 @@ make_reason(String const& reason,
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
s.append(fs::path{file}.filename().string()); s.append(fs::path{file}.filename().string());
s.append("("); s.append("(");
s.append(std::to_string(line)); s.append(boost::lexical_cast<std::string>(line));
s.append(")"); s.append(")");
return s; return s;
} }

View File

@ -199,8 +199,8 @@ prepare(message<isRequest, Body, Headers>& msg,
if(*pi.content_length > 0 || if(*pi.content_length > 0 ||
ci_equal(msg.method, "POST")) ci_equal(msg.method, "POST"))
{ {
msg.headers.insert("Content-Length", msg.headers.insert(
std::to_string(*pi.content_length)); "Content-Length", *pi.content_length);
} }
} }
@ -212,8 +212,8 @@ prepare(message<isRequest, Body, Headers>& msg,
msg.status != 204 && msg.status != 204 &&
msg.status != 304) msg.status != 304)
{ {
msg.headers.insert("Content-Length", msg.headers.insert(
std::to_string(*pi.content_length)); "Content-Length", *pi.content_length);
} }
} }
}; };

View File

@ -9,6 +9,7 @@
#include <beast/http/basic_headers.hpp> #include <beast/http/basic_headers.hpp>
#include <beast/unit_test/suite.hpp> #include <beast/unit_test/suite.hpp>
#include <boost/lexical_cast.hpp>
namespace beast { namespace beast {
namespace http { namespace http {
@ -27,7 +28,7 @@ public:
fill(std::size_t n, basic_headers<Allocator>& h) fill(std::size_t n, basic_headers<Allocator>& h)
{ {
for(std::size_t i = 1; i<= n; ++i) for(std::size_t i = 1; i<= n; ++i)
h.insert(std::to_string(i), i); h.insert(boost::lexical_cast<std::string>(i), i);
} }
template<class U, class V> template<class U, class V>

View File

@ -11,6 +11,7 @@
#include <beast/core/placeholders.hpp> #include <beast/core/placeholders.hpp>
#include <beast/core/streambuf.hpp> #include <beast/core/streambuf.hpp>
#include <beast/websocket.hpp> #include <beast/websocket.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
@ -277,7 +278,7 @@ private:
d.state = 1; d.state = 1;
d.ws.async_handshake( d.ws.async_handshake(
d.ep->address().to_string() + ":" + d.ep->address().to_string() + ":" +
std::to_string(d.ep->port()), boost::lexical_cast<std::string>(d.ep->port()),
"/", d.strand.wrap(std::move(*this))); "/", d.strand.wrap(std::move(*this)));
return; return;
} }

View File

@ -11,6 +11,7 @@
#include <beast/core/placeholders.hpp> #include <beast/core/placeholders.hpp>
#include <beast/core/streambuf.hpp> #include <beast/core/streambuf.hpp>
#include <beast/websocket.hpp> #include <beast/websocket.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <functional> #include <functional>
#include <iostream> #include <iostream>
@ -84,7 +85,7 @@ private:
fail(int id, error_code ec, std::string what) fail(int id, error_code ec, std::string what)
{ {
if(log_) if(log_)
std::cerr << "#" << std::to_string(id) << " " << std::cerr << "#" << boost::lexical_cast<std::string>(id) << " " <<
what << ": " << ec.message() << std::endl; what << ": " << ec.message() << std::endl;
} }