Skip to content

Commit 36cf176

Browse files
author
Jussi Lyytinen
committed
Made as_optional() visible to MSVC builds only
1 parent 5368f89 commit 36cf176

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

boost/network/protocol/http/algorithms/linearize.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <boost/optional.hpp>
2020
#include <boost/range/algorithm/copy.hpp>
2121
#include <boost/algorithm/string/compare.hpp>
22+
#include <boost/version.hpp>
2223

2324
namespace boost {
2425
namespace network {
@@ -138,7 +139,12 @@ BOOST_CONCEPT_REQUIRES(((ClientRequest<Request>)), (OutputIterator))
138139
*oi = consts::colon_char();
139140
*oi = consts::space_char();
140141
boost::copy(request.host(), oi);
141-
boost::optional<boost::uint16_t> port_ = port(request).as_optional();
142+
boost::optional<boost::uint16_t> port_ =
143+
#if (_MSC_VER >= 1600 && BOOST_VERSION > 105500)
144+
port(request).as_optional();
145+
#else
146+
port(request);
147+
#endif
142148
if (port_) {
143149
string_type port_str = boost::lexical_cast<string_type>(*port_);
144150
*oi = consts::colon_char();

boost/network/protocol/http/message/wrappers/port.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <boost/optional.hpp>
1313
#include <boost/cstdint.hpp>
1414
#include <boost/network/uri/accessors.hpp>
15+
#include <boost/version.hpp>
1516

1617
namespace boost {
1718
namespace network {
@@ -32,21 +33,19 @@ struct port_wrapper {
3233

3334
operator port_type() const { return message_.port(); }
3435

35-
#if !defined(_MSC_VER)
36+
#if (_MSC_VER >= 1600 && BOOST_VERSION > 105500)
3637
// Because of a breaking change in Boost 1.56 to boost::optional, implicit
3738
// conversions no longer work correctly with MSVC. The conversion therefore
38-
// has to be done explicitly with as_optional(). This method is here just
39-
// to maintain backwards compatibility with compilers not affected by the
40-
// change.
41-
operator boost::optional<boost::uint16_t>() const {
39+
// has to be done explicitly with as_optional().
40+
boost::optional<boost::uint16_t> as_optional() const {
4241
return uri::port_us(message_.uri());
4342
}
44-
#endif
45-
46-
boost::optional<boost::uint16_t> as_optional() const {
43+
#else
44+
operator boost::optional<boost::uint16_t>() const {
4745
return uri::port_us(message_.uri());
4846
}
49-
47+
#endif
48+
5049
};
5150

5251
} // namespace impl

0 commit comments

Comments
 (0)