mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-28 15:14:11 +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:
parent
68e270b029
commit
9d4da1ad2e
@ -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>
|
||||
|
@ -106,9 +106,9 @@ struct object {
|
||||
T as() const;
|
||||
|
||||
template <typename T>
|
||||
void convert(T& v) const;
|
||||
T& convert(T& v) const;
|
||||
template <typename T>
|
||||
void convert(T* v) const;
|
||||
T* convert(T* v) const;
|
||||
|
||||
object();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user