Skip to content

Commit 87f0da1

Browse files
author
Dainis Jonitis
committed
Support vectors of non-default-constructible values in c++11 mode
1 parent 1b13523 commit 87f0da1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

include/msgpack/adaptor/vector.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
3232

3333
namespace adaptor {
3434

35+
#if !defined(MSGPACK_USE_CPP03)
36+
template <typename T>
37+
struct as<std::vector<T>> {
38+
std::vector<T> operator()(const msgpack::object& o) const {
39+
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
40+
std::vector<T> v;
41+
if (o.via.array.size > 0) {
42+
msgpack::object* p = o.via.array.ptr;
43+
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
44+
do {
45+
v.emplace_back(p->as<T>());
46+
++p;
47+
} while (p < pend);
48+
}
49+
return v;
50+
}
51+
};
52+
#endif
53+
3554
template <typename T>
3655
struct convert<std::vector<T> > {
3756
msgpack::object const& operator()(msgpack::object const& o, std::vector<T>& v) const {

0 commit comments

Comments
 (0)