Skip to content

Commit 83f0429

Browse files
committed
Merge pull request #408 from redboltz/replace_nil_with_nil_t
Replaced nil with nil_t.
2 parents 6c035f7 + ed5a412 commit 83f0429

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

include/msgpack/adaptor/boost/msgpack_variant.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace type {
4343
template <typename STR, typename BIN, typename EXT>
4444
struct basic_variant :
4545
boost::variant<
46-
nil, // NIL
46+
nil_t, // NIL
4747
bool, // BOOL
4848
int64_t, // NEGATIVE_INTEGER
4949
uint64_t, // POSITIVE_INTEGER
@@ -62,7 +62,7 @@ struct basic_variant :
6262
>,
6363
private boost::totally_ordered<basic_variant<STR, BIN, EXT> > {
6464
typedef boost::variant<
65-
nil, // NIL
65+
nil_t, // NIL
6666
bool, // BOOL
6767
int64_t, // NEGATIVE_INTEGER
6868
uint64_t, // POSITIVE_INTEGER
@@ -104,7 +104,7 @@ struct basic_variant :
104104
basic_variant(unsigned long long v):base(uint64_t(v)) {}
105105

106106
bool is_nil() const {
107-
return boost::get<nil>(this);
107+
return boost::get<msgpack::type::nil_t>(this);
108108
}
109109
bool is_bool() const {
110110
return boost::get<bool>(this);
@@ -268,7 +268,7 @@ struct as<msgpack::type::basic_variant<STR, BIN, EXT> > {
268268
msgpack::type::basic_variant<STR, BIN, EXT> operator()(msgpack::object const& o) const {
269269
switch(o.type) {
270270
case type::NIL:
271-
return o.as<msgpack::type::nil>();
271+
return o.as<msgpack::type::nil_t>();
272272
case type::BOOLEAN:
273273
return o.as<bool>();
274274
case type::POSITIVE_INTEGER:
@@ -304,7 +304,7 @@ struct convert<msgpack::type::basic_variant<STR, BIN, EXT> > {
304304
msgpack::type::basic_variant<STR, BIN, EXT>& v) const {
305305
switch(o.type) {
306306
case type::NIL:
307-
v = o.as<msgpack::type::nil>();
307+
v = o.as<msgpack::type::nil_t>();
308308
break;
309309
case type::BOOLEAN:
310310
v = o.as<bool>();
@@ -366,8 +366,8 @@ struct pack<msgpack::type::basic_variant<STR, BIN, EXT> > {
366366
namespace detail {
367367

368368
struct object_imp : boost::static_visitor<void> {
369-
void operator()(msgpack::type::nil const& v) const {
370-
object<msgpack::type::nil>()(o_, v);
369+
void operator()(msgpack::type::nil_t const& v) const {
370+
object<msgpack::type::nil_t>()(o_, v);
371371
}
372372
void operator()(bool const& v) const {
373373
object<bool>()(o_, v);

include/msgpack/adaptor/nil.hpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
2121

2222
namespace type {
2323

24-
struct nil { };
24+
struct nil_t { };
2525

26-
inline bool operator<(nil const& lhs, nil const& rhs) {
26+
#if defined(MSGPACK_USE_LEGACY_NIL)
27+
28+
typedef nil_t nil;
29+
30+
#endif // defined(MSGPACK_USE_LEGACY_NIL)
31+
32+
inline bool operator<(nil_t const& lhs, nil_t const& rhs) {
2733
return &lhs < &rhs;
2834
}
2935

30-
inline bool operator==(nil const& lhs, nil const& rhs) {
36+
inline bool operator==(nil_t const& lhs, nil_t const& rhs) {
3137
return &lhs == &rhs;
3238
}
3339

@@ -36,32 +42,32 @@ inline bool operator==(nil const& lhs, nil const& rhs) {
3642
namespace adaptor {
3743

3844
template <>
39-
struct convert<type::nil> {
40-
msgpack::object const& operator()(msgpack::object const& o, type::nil&) const {
45+
struct convert<type::nil_t> {
46+
msgpack::object const& operator()(msgpack::object const& o, type::nil_t&) const {
4147
if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); }
4248
return o;
4349
}
4450
};
4551

4652
template <>
47-
struct pack<type::nil> {
53+
struct pack<type::nil_t> {
4854
template <typename Stream>
49-
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil&) const {
55+
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil_t&) const {
5056
o.pack_nil();
5157
return o;
5258
}
5359
};
5460

5561
template <>
56-
struct object<type::nil> {
57-
void operator()(msgpack::object& o, type::nil) const {
62+
struct object<type::nil_t> {
63+
void operator()(msgpack::object& o, type::nil_t) const {
5864
o.type = msgpack::type::NIL;
5965
}
6066
};
6167

6268
template <>
63-
struct object_with_zone<type::nil> {
64-
void operator()(msgpack::object::with_zone& o, type::nil v) const {
69+
struct object_with_zone<type::nil_t> {
70+
void operator()(msgpack::object::with_zone& o, type::nil_t v) const {
6571
static_cast<msgpack::object&>(o) << v;
6672
}
6773
};
@@ -71,7 +77,7 @@ struct object_with_zone<type::nil> {
7177
template <>
7278
inline void msgpack::object::as<void>() const
7379
{
74-
msgpack::type::nil v;
80+
msgpack::type::nil_t v;
7581
convert(v);
7682
}
7783

test/boost_variant.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,36 @@ const double kEPS = 1e-10;
1717
TEST(MSGPACK_BOOST, pack_convert_variant_nil)
1818
{
1919
std::stringstream ss;
20-
msgpack::type::variant val1 = msgpack::type::nil();
20+
msgpack::type::variant val1 = msgpack::type::nil_t();
2121
EXPECT_TRUE(val1.is_nil());
2222
msgpack::pack(ss, val1);
2323

2424
msgpack::unpacked ret;
2525
msgpack::unpack(ret, ss.str().data(), ss.str().size());
2626
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
2727
EXPECT_TRUE(val2.is_nil());
28-
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
28+
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
2929
}
3030

3131
TEST(MSGPACK_BOOST, object_variant_nil)
3232
{
33-
msgpack::type::variant val1 = msgpack::type::nil();
33+
msgpack::type::variant val1 = msgpack::type::nil_t();
3434
EXPECT_TRUE(val1.is_nil());
3535
msgpack::object obj(val1);
3636
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
3737
EXPECT_TRUE(val2.is_nil());
38-
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
38+
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
3939
}
4040

4141
TEST(MSGPACK_BOOST, object_with_zone_variant_nil)
4242
{
4343
msgpack::zone z;
44-
msgpack::type::variant val1 = msgpack::type::nil();
44+
msgpack::type::variant val1 = msgpack::type::nil_t();
4545
EXPECT_TRUE(val1.is_nil());
4646
msgpack::object obj(val1, z);
4747
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
4848
EXPECT_TRUE(val2.is_nil());
49-
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
49+
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
5050
}
5151

5252
// nil (default constructor)
@@ -63,7 +63,7 @@ TEST(MSGPACK_BOOST, pack_convert_variant_nil_default)
6363
msgpack::unpack(ret, ss.str().data(), ss.str().size());
6464
msgpack::type::variant val2 = ret.get().as<msgpack::type::variant>();
6565
EXPECT_TRUE(val2.is_nil());
66-
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
66+
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
6767
}
6868

6969
TEST(MSGPACK_BOOST, object_variant_nil_default)
@@ -73,7 +73,7 @@ TEST(MSGPACK_BOOST, object_variant_nil_default)
7373
msgpack::object obj(val1);
7474
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
7575
EXPECT_TRUE(val2.is_nil());
76-
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
76+
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
7777
}
7878

7979
TEST(MSGPACK_BOOST, object_with_zone_variant_nil_default)
@@ -84,7 +84,7 @@ TEST(MSGPACK_BOOST, object_with_zone_variant_nil_default)
8484
msgpack::object obj(val1, z);
8585
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
8686
EXPECT_TRUE(val2.is_nil());
87-
EXPECT_NO_THROW(boost::get<msgpack::type::nil>(val2));
87+
EXPECT_NO_THROW(boost::get<msgpack::type::nil_t>(val2));
8888
}
8989

9090
// bool

0 commit comments

Comments
 (0)