Skip to content

Commit 9d4da1a

Browse files
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.
1 parent 68e270b commit 9d4da1a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

include/msgpack/object.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,17 @@ inline msgpack::object::implicit_type object::convert() const
386386
}
387387

388388
template <typename T>
389-
inline void object::convert(T& v) const
389+
inline T& object::convert(T& v) const
390390
{
391391
msgpack::operator>>(*this, v);
392+
return v;
392393
}
393394

394395
template <typename T>
395-
inline void object::convert(T* v) const
396+
inline T* object::convert(T* v) const
396397
{
397398
convert(*v);
399+
return v;
398400
}
399401

400402
template <typename T>

include/msgpack/object_fwd.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ struct object {
106106
T as() const;
107107

108108
template <typename T>
109-
void convert(T& v) const;
109+
T& convert(T& v) const;
110110
template <typename T>
111-
void convert(T* v) const;
111+
T* convert(T* v) const;
112112

113113
object();
114114

0 commit comments

Comments
 (0)