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:
David Chappelle 2015-05-15 16:21:54 -04:00
parent 68e270b029
commit 9d4da1ad2e
2 changed files with 6 additions and 4 deletions

View File

@ -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>

View File

@ -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();