Skip to content

Commit df5f84d

Browse files
committed
Added totally ordered.
1 parent 0609347 commit df5f84d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

include/msgpack/adaptor/boost/msgpack_variant.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "msgpack/adaptor/map.hpp"
3838

3939
#include <boost/variant.hpp>
40+
#include <boost/operators.hpp>
4041

4142
namespace msgpack {
4243

@@ -70,7 +71,7 @@ typedef boost::variant<
7071

7172
} // namespace detail
7273

73-
struct variant : detail::variant_imp {
74+
struct variant : detail::variant_imp, private boost::totally_ordered<variant> {
7475
typedef detail::variant_imp base;
7576
variant() {}
7677
template <typename T>
@@ -115,6 +116,7 @@ inline bool operator==(variant const& lhs, variant const& rhs) {
115116
return static_cast<variant::base const&>(lhs) == static_cast<variant::base const&>(rhs);
116117
}
117118

119+
118120
struct variant_ref;
119121

120122
namespace detail {
@@ -139,7 +141,7 @@ typedef boost::variant<
139141

140142
} // namespace detail
141143

142-
struct variant_ref : detail::variant_ref_imp {
144+
struct variant_ref : detail::variant_ref_imp, private boost::totally_ordered<variant_ref> {
143145
typedef detail::variant_ref_imp base;
144146
variant_ref() {}
145147
template <typename T>

test/boost_variant.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ TEST(MSGPACK_BOOST, pack_convert_variant_bool)
8787
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
8888
EXPECT_NO_THROW(boost::get<bool>(val2));
8989
EXPECT_TRUE(val1 == val2);
90+
// Tests for totally ordered
91+
EXPECT_FALSE(val1 != val2);
92+
EXPECT_FALSE(val1 < val2);
93+
EXPECT_FALSE(val1 > val2);
94+
EXPECT_TRUE(val1 <= val2);
95+
EXPECT_TRUE(val1 >= val2);
9096
}
9197

9298
TEST(MSGPACK_BOOST, object_variant_bool)

0 commit comments

Comments
 (0)