44// Copyright 2010, 2014 Dean Michael Berris <[email protected] >55// Copyright 2010 (c) Sinefunc, Inc.
66// Copyright 2014 Google, Inc.
7+ // Copyright 2014 Jussi Lyytinen
78// Distributed under the Boost Software License, Version 1.0.
89// (See accompanying file LICENSE_1_0.txt or copy at
910// http://www.boost.org/LICENSE_1_0.txt)
1011
1112#include < boost/optional.hpp>
1213#include < boost/cstdint.hpp>
1314#include < boost/network/uri/accessors.hpp>
15+ #include < boost/version.hpp>
1416
1517namespace boost {
1618namespace network {
@@ -31,24 +33,19 @@ struct port_wrapper {
3133
3234 operator port_type () const { return message_.port (); }
3335
34- #if (_MSC_VER >= 1600)
35- // We hack this so that we don't run into the issue of MSVC 2010 not doing the
36- // right thing when converting/copying Boost.Optional objects.
37- struct optional_wrapper {
38- boost::optional<boost::uint16_t > o_;
39- explicit optional_wrapper (boost::optional<boost::uint16_t > o) : o_(o) {}
40- operator boost::optional<boost::uint16_t >() const { return o_; }
41- };
42-
43- operator optional_wrapper () const {
44- return optional_wrapper (uri::port_us (message_.uri ()));
36+ #if (_MSC_VER >= 1600 && BOOST_VERSION > 105500)
37+ // Because of a breaking change in Boost 1.56 to boost::optional, implicit
38+ // conversions no longer work correctly with MSVC. The conversion therefore
39+ // has to be done explicitly with as_optional().
40+ boost::optional<boost::uint16_t > as_optional () const {
41+ return uri::port_us (message_.uri ());
4542 }
4643#else
4744 operator boost::optional<boost::uint16_t >() const {
4845 return uri::port_us (message_.uri ());
4946 }
5047#endif
51-
48+
5249};
5350
5451} // namespace impl
0 commit comments