4
4
// Copyright 2010, 2014 Dean Michael Berris <dberris@google.com>
5
5
// Copyright 2010 (c) Sinefunc, Inc.
6
6
// Copyright 2014 Google, Inc.
7
+ // Copyright 2014 Jussi Lyytinen
7
8
// Distributed under the Boost Software License, Version 1.0.
8
9
// (See accompanying file LICENSE_1_0.txt or copy at
9
10
// http://www.boost.org/LICENSE_1_0.txt)
10
11
11
12
#include < boost/optional.hpp>
12
13
#include < boost/cstdint.hpp>
13
14
#include < boost/network/uri/accessors.hpp>
15
+ #include < boost/version.hpp>
14
16
15
17
namespace boost {
16
18
namespace network {
@@ -31,24 +33,19 @@ struct port_wrapper {
31
33
32
34
operator port_type () const { return message_.port (); }
33
35
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 ());
45
42
}
46
43
#else
47
44
operator boost::optional<boost::uint16_t >() const {
48
45
return uri::port_us (message_.uri ());
49
46
}
50
47
#endif
51
-
48
+
52
49
};
53
50
54
51
} // namespace impl
0 commit comments