marshall& operator<<(marshall &, unsigned long long);
marshall& operator<<(marshall &, const std::string &);
-template <class C> marshall &
-operator<<(marshall &m, std::vector<C> v)
-{
- m << (unsigned int) v.size();
- for(unsigned i = 0; i < v.size(); i++)
- m << v[i];
- return m;
-}
-
-template <class A, class B> marshall &
-operator<<(marshall &m, const std::map<A,B> &d) {
- typename std::map<A,B>::const_iterator i;
-
- m << (unsigned int) d.size();
-
- for (i = d.begin(); i != d.end(); i++) {
- m << i->first << i->second;
- }
- return m;
-}
-
template <class A> marshall &
-operator<<(marshall &m, const std::list<A> &d) {
- m << std::vector<A>(d.begin(), d.end());
+operator<<(marshall &m, const A &x) {
+ m << (unsigned int) x.size();
+ for (const auto &a : x)
+ m << a;
return m;
}
unmarshall& operator>>(unmarshall &, unsigned long long &);
unmarshall& operator>>(unmarshall &, std::string &);
-template <class C> unmarshall &
-operator>>(unmarshall &u, std::vector<C> &v)
-{
- unsigned n;
- u >> n;
- v.clear();
- while (n--) {
- C c;
- u >> c;
- v.push_back(c);
- }
- return u;
-}
-
-template <class A, class B> unmarshall &
-operator>>(unmarshall &u, std::map<A,B> &d) {
- unsigned n;
- u >> n;
- d.clear();
- while (n--) {
- A a;
- B b;
- u >> a >> b;
- d[a] = b;
- }
+template <class A> unmarshall & operator>>(unmarshall &u, A &x) {
+ unsigned n = u.grab<unsigned>();
+ x.clear();
+ while (n--)
+ x.emplace_back(u.grab<typename A::value_type>());
return u;
}
-template <class C> unmarshall &
-operator>>(unmarshall &u, std::list<C> &l) {
- unsigned n;
- u >> n;
- l.clear();
- while (n--) {
- C c;
- u >> c;
- l.push_back(c);
- }
+template <class A, class B> unmarshall &
+operator>>(unmarshall &u, std::map<A,B> &x) {
+ unsigned n = u.grab<unsigned>();
+ x.clear();
+ while (n--)
+ x.emplace(u.grab<std::pair<A,B>>());
return u;
}