From 5368f8989a79a189eff8d778092b6bd556fb5ea4 Mon Sep 17 00:00:00 2001 From: Jussi Lyytinen Date: Tue, 16 Sep 2014 12:25:51 +0300 Subject: [PATCH 1/2] Fix for issue #419 --- .../protocol/http/algorithms/linearize.hpp | 3 ++- .../protocol/http/message/wrappers/port.hpp | 24 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/boost/network/protocol/http/algorithms/linearize.hpp b/boost/network/protocol/http/algorithms/linearize.hpp index 4f91cce64..53340d7be 100644 --- a/boost/network/protocol/http/algorithms/linearize.hpp +++ b/boost/network/protocol/http/algorithms/linearize.hpp @@ -2,6 +2,7 @@ #define BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028 // Copyright 2010 Dean Michael Berris. +// Copyright 2014 Jussi Lyytinen // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -137,7 +138,7 @@ BOOST_CONCEPT_REQUIRES(((ClientRequest)), (OutputIterator)) *oi = consts::colon_char(); *oi = consts::space_char(); boost::copy(request.host(), oi); - boost::optional port_ = port(request); + boost::optional port_ = port(request).as_optional(); if (port_) { string_type port_str = boost::lexical_cast(*port_); *oi = consts::colon_char(); diff --git a/boost/network/protocol/http/message/wrappers/port.hpp b/boost/network/protocol/http/message/wrappers/port.hpp index ac00a61c0..0934925d9 100644 --- a/boost/network/protocol/http/message/wrappers/port.hpp +++ b/boost/network/protocol/http/message/wrappers/port.hpp @@ -4,6 +4,7 @@ // Copyright 2010, 2014 Dean Michael Berris // Copyright 2010 (c) Sinefunc, Inc. // Copyright 2014 Google, Inc. +// Copyright 2014 Jussi Lyytinen // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -31,23 +32,20 @@ struct port_wrapper { operator port_type() const { return message_.port(); } -#if (_MSC_VER >= 1600) - // We hack this so that we don't run into the issue of MSVC 2010 not doing the - // right thing when converting/copying Boost.Optional objects. - struct optional_wrapper { - boost::optional o_; - explicit optional_wrapper(boost::optional o) : o_(o) {} - operator boost::optional() const { return o_; } - }; - - operator optional_wrapper() const { - return optional_wrapper(uri::port_us(message_.uri())); - } -#else +#if !defined(_MSC_VER) + // Because of a breaking change in Boost 1.56 to boost::optional, implicit + // conversions no longer work correctly with MSVC. The conversion therefore + // has to be done explicitly with as_optional(). This method is here just + // to maintain backwards compatibility with compilers not affected by the + // change. operator boost::optional() const { return uri::port_us(message_.uri()); } #endif + + boost::optional as_optional() const { + return uri::port_us(message_.uri()); + } }; From 36cf1762605c1379e605545e40be3d8ff24fe194 Mon Sep 17 00:00:00 2001 From: Jussi Lyytinen Date: Thu, 18 Sep 2014 17:21:39 +0300 Subject: [PATCH 2/2] Made as_optional() visible to MSVC builds only --- .../protocol/http/algorithms/linearize.hpp | 8 +++++++- .../protocol/http/message/wrappers/port.hpp | 17 ++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/boost/network/protocol/http/algorithms/linearize.hpp b/boost/network/protocol/http/algorithms/linearize.hpp index 53340d7be..d0347fd04 100644 --- a/boost/network/protocol/http/algorithms/linearize.hpp +++ b/boost/network/protocol/http/algorithms/linearize.hpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace boost { namespace network { @@ -138,7 +139,12 @@ BOOST_CONCEPT_REQUIRES(((ClientRequest)), (OutputIterator)) *oi = consts::colon_char(); *oi = consts::space_char(); boost::copy(request.host(), oi); - boost::optional port_ = port(request).as_optional(); + boost::optional port_ = +#if (_MSC_VER >= 1600 && BOOST_VERSION > 105500) + port(request).as_optional(); +#else + port(request); +#endif if (port_) { string_type port_str = boost::lexical_cast(*port_); *oi = consts::colon_char(); diff --git a/boost/network/protocol/http/message/wrappers/port.hpp b/boost/network/protocol/http/message/wrappers/port.hpp index 0934925d9..f05d9dc81 100644 --- a/boost/network/protocol/http/message/wrappers/port.hpp +++ b/boost/network/protocol/http/message/wrappers/port.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace network { @@ -32,21 +33,19 @@ struct port_wrapper { operator port_type() const { return message_.port(); } -#if !defined(_MSC_VER) +#if (_MSC_VER >= 1600 && BOOST_VERSION > 105500) // Because of a breaking change in Boost 1.56 to boost::optional, implicit // conversions no longer work correctly with MSVC. The conversion therefore - // has to be done explicitly with as_optional(). This method is here just - // to maintain backwards compatibility with compilers not affected by the - // change. - operator boost::optional() const { + // has to be done explicitly with as_optional(). + boost::optional as_optional() const { return uri::port_us(message_.uri()); } -#endif - - boost::optional as_optional() const { +#else + operator boost::optional() const { return uri::port_us(message_.uri()); } - +#endif + }; } // namespace impl