Skip to content

Commit

Permalink
Support vectors of non-default-constructible values in c++11 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Dainis Jonitis committed Jul 27, 2015
1 parent 1b13523 commit 87f0da1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/msgpack/adaptor/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {

namespace adaptor {

#if !defined(MSGPACK_USE_CPP03)
template <typename T>
struct as<std::vector<T>> {
std::vector<T> operator()(const msgpack::object& o) const {
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
std::vector<T> v;
if (o.via.array.size > 0) {
msgpack::object* p = o.via.array.ptr;
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
do {
v.emplace_back(p->as<T>());
++p;
} while (p < pend);
}
return v;
}
};
#endif

template <typename T>
struct convert<std::vector<T> > {
msgpack::object const& operator()(msgpack::object const& o, std::vector<T>& v) const {
Expand Down

0 comments on commit 87f0da1

Please sign in to comment.