Added * and -> operators to object_handle

This commit is contained in:
sztomi 2017-10-09 20:23:25 +02:00
parent b02c6beb4d
commit d452625ed1
2 changed files with 21 additions and 0 deletions

View File

@ -70,6 +70,18 @@ public:
const msgpack::object& get() const const msgpack::object& get() const
{ return m_obj; } { return m_obj; }
/**
* @return object (to mimic smart pointers).
*/
const msgpack::object& operator*() const
{ return get(); }
/**
* @return the address of the object (to mimic smart pointers).
*/
const msgpack::object* operator->() const
{ return &get(); }
/// Get unique_ptr reference of zone. /// Get unique_ptr reference of zone.
/** /**
* @return unique_ptr reference of zone * @return unique_ptr reference of zone

View File

@ -445,3 +445,12 @@ TEST(object, pack_double)
EXPECT_EQ(static_cast<size_t>(9), ss1.str().size()); EXPECT_EQ(static_cast<size_t>(9), ss1.str().size());
EXPECT_EQ(ss1.str(), ss2.str()); EXPECT_EQ(ss1.str(), ss2.str());
} }
TEST(object, handle_operators)
{
int i = 1;
msgpack::object obj(i);
msgpack::object_handle oh = msgpack::clone(obj);
EXPECT_EQ(oh.get(), *oh);
EXPECT_EQ(oh->as<int>(), oh.get().as<int>());
}