Skip to content

Commit

Permalink
Merge pull request #279 from jpetso/master
Browse files Browse the repository at this point in the history
Use std::move (C++11) in map and set adaptors where possible.
  • Loading branch information
redboltz committed May 18, 2015
2 parents 68e270b + 9725bac commit 432c9cc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
8 changes: 4 additions & 4 deletions include/msgpack/adaptor/cpp11/unordered_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ struct convert<std::unordered_map<K, V>> {
for(; p != pend; ++p) {
K key;
p->key.convert(key);
p->val.convert(tmp[key]);
p->val.convert(tmp[std::move(key)]);
}
tmp.swap(v);
v = std::move(tmp);
return o;
}
};
Expand Down Expand Up @@ -100,9 +100,9 @@ struct convert<std::unordered_multimap<K, V>> {
std::pair<K, V> value;
p->key.convert(value.first);
p->val.convert(value.second);
tmp.insert(value);
tmp.insert(std::move(value));
}
tmp.swap(v);
v = std::move(tmp);
return o;
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/msgpack/adaptor/cpp11/unordered_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct convert<std::unordered_set<T>> {
--p;
tmp.insert(p->as<T>());
}
tmp.swap(v);
v = std::move(tmp);
return o;
}
};
Expand Down Expand Up @@ -97,7 +97,7 @@ struct convert<std::unordered_multiset<T>> {
--p;
tmp.insert(p->as<T>());
}
tmp.swap(v);
v = std::move(tmp);
return o;
}
};
Expand Down
25 changes: 17 additions & 8 deletions include/msgpack/adaptor/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,17 @@ struct convert<std::map<K, V> > {
for(; p != pend; ++p) {
K key;
p->key.convert(key);
typename std::map<K,V>::iterator it(tmp.lower_bound(key));
if(it != tmp.end() && !(key < it->first)) {
p->val.convert(it->second);
} else {
V val;
p->val.convert(val);
tmp.insert(it, std::pair<K,V>(key, val));
}
#if __cplusplus >= 201103L
p->val.convert(tmp[std::move(key)]);
#else
p->val.convert(tmp[key]);
#endif
}
#if __cplusplus >= 201103L
v = std::move(tmp);
#else
tmp.swap(v);
#endif
return o;
}
};
Expand Down Expand Up @@ -180,9 +181,17 @@ struct convert<std::multimap<K, V> > {
std::pair<K, V> value;
p->key.convert(value.first);
p->val.convert(value.second);
#if __cplusplus >= 201103L
tmp.insert(std::move(value));
#else
tmp.insert(value);
#endif
}
#if __cplusplus >= 201103L
v = std::move(tmp);
#else
tmp.swap(v);
#endif
return o;
}
};
Expand Down
8 changes: 8 additions & 0 deletions include/msgpack/adaptor/set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ struct convert<std::set<T> > {
--p;
tmp.insert(p->as<T>());
}
#if __cplusplus >= 201103L
v = std::move(tmp);
#else
tmp.swap(v);
#endif
return o;
}
};
Expand Down Expand Up @@ -96,7 +100,11 @@ struct convert<std::multiset<T> > {
--p;
tmp.insert(p->as<T>());
}
#if __cplusplus >= 201103L
v = std::move(tmp);
#else
tmp.swap(v);
#endif
return o;
}
};
Expand Down

0 comments on commit 432c9cc

Please sign in to comment.