mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-15 15:16:51 +02:00
Object conversions return the specific type that was converted.
This allows us to easily make function calls that have parameters that are dependent upon converting from msgpack objects to concrete types. For example: void process_args(std::tuple<int,std::string>& args) { ... } process_args(obj.convert(std::make_tuple(100,"hello"))) You can get similar behavior by using obj.as<...>() but its performance is highly dependent upon the specific compiler and whether or not r-value references are supported.
This commit is contained in:
@@ -386,15 +386,17 @@ inline msgpack::object::implicit_type object::convert() const
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void object::convert(T& v) const
|
||||
inline T& object::convert(T& v) const
|
||||
{
|
||||
msgpack::operator>>(*this, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void object::convert(T* v) const
|
||||
inline T* object::convert(T* v) const
|
||||
{
|
||||
convert(*v);
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
Reference in New Issue
Block a user