@@ -1128,6 +1128,38 @@ namespace madness {
1128
1128
}
1129
1129
};
1130
1130
1131
+ // / Serialize a \c std::allocator.
1132
+
1133
+ // / This is a no-op.
1134
+ // / \tparam Archive the archive type.
1135
+ // / \tparam T The data type allocated by the \c allocator.
1136
+ template <class Archive , typename T>
1137
+ struct ArchiveStoreImpl < Archive, std::allocator<T>, std::enable_if_t <!is_future<T>::value && is_serializable_v<Archive, T>> > {
1138
+
1139
+ // / Storing a \c std::allocator is a no-op
1140
+
1141
+ // / \param[in] ar The archive.
1142
+ // / \param[in] v The \c allocator.
1143
+ static inline void store (const Archive& ar, const std::allocator<T>& v) {
1144
+ }
1145
+ };
1146
+
1147
+
1148
+ // / Deserialize a \c std::allocator.
1149
+
1150
+ // / This is a no-op.
1151
+ // / \tparam Archive the archive type.
1152
+ // / \tparam T The data type alllocated by in the \c allocator.
1153
+ template <class Archive , typename T>
1154
+ struct ArchiveLoadImpl < Archive, std::allocator<T>, std::enable_if_t <!is_future<T>::value && is_serializable_v<Archive, T>> > {
1155
+
1156
+ // / Loading a \c std::allocator is a no-op
1157
+
1158
+ // / \param[in] ar The archive.
1159
+ // / \param[out] v The \c allocator.
1160
+ static void load (const Archive& ar, std::allocator<T>& v) {
1161
+ }
1162
+ };
1131
1163
1132
1164
// / Serialize a \c std::vector.
1133
1165
@@ -1143,6 +1175,9 @@ namespace madness {
1143
1175
// / \param[in] v The \c vector.
1144
1176
static inline void store (const Archive& ar, const std::vector<T, Alloc>& v) {
1145
1177
MAD_ARCHIVE_DEBUG (std::cout << " serialize std::vector of plain data" << std::endl);
1178
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1179
+ ar & v.get_allocator ();
1180
+ }
1146
1181
ar & v.size ();
1147
1182
ar & wrap (v.data (),v.size ());
1148
1183
}
@@ -1164,6 +1199,11 @@ namespace madness {
1164
1199
// / \param[out] v The \c vector.
1165
1200
static void load (const Archive& ar, std::vector<T, Alloc>& v) {
1166
1201
MAD_ARCHIVE_DEBUG (std::cout << " deserialize std::vector of plain data" << std::endl);
1202
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1203
+ Alloc allocator;
1204
+ ar & allocator;
1205
+ v = std::vector<T, Alloc>(allocator);
1206
+ }
1167
1207
std::size_t n = 0ul ;
1168
1208
ar & n;
1169
1209
if (n != v.size ()) {
@@ -1188,6 +1228,9 @@ namespace madness {
1188
1228
// / \param[in] v The \c vector.
1189
1229
static inline void store (const Archive& ar, const std::vector<bool , Alloc>& v) {
1190
1230
MAD_ARCHIVE_DEBUG (std::cout << " serialize std::vector<bool>" << std::endl);
1231
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1232
+ ar & v.get_allocator ();
1233
+ }
1191
1234
std::size_t n = v.size ();
1192
1235
bool * b = new bool [n];
1193
1236
for (std::size_t i=0 ; i<n; ++i) b[i] = v[i];
@@ -1210,6 +1253,11 @@ namespace madness {
1210
1253
// / \param[out] v The \c vector.
1211
1254
static void load (const Archive& ar, std::vector<bool , Alloc>& v) {
1212
1255
MAD_ARCHIVE_DEBUG (std::cout << " deserialize std::vector<bool>" << std::endl);
1256
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1257
+ Alloc allocator;
1258
+ ar & allocator;
1259
+ v = std::vector<bool , Alloc>(allocator);
1260
+ }
1213
1261
std::size_t n = 0ul ;
1214
1262
ar & n;
1215
1263
if (n != v.size ()) {
@@ -1403,6 +1451,9 @@ namespace madness {
1403
1451
// / \param[in] t The \c map.
1404
1452
static void store (const Archive& ar, const std::map<T,Q,Compare,Alloc>& t) {
1405
1453
MAD_ARCHIVE_DEBUG (std::cout << " serialize std::map" << std::endl);
1454
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1455
+ ar & t.get_allocator ();
1456
+ }
1406
1457
ar << t.size ();
1407
1458
for (auto p = t.begin ();
1408
1459
p != t.end (); ++p) {
@@ -1434,12 +1485,19 @@ namespace madness {
1434
1485
// / \param[out] t The \c map.
1435
1486
static void load (const Archive& ar, std::map<T,Q,Compare,Alloc>& t) {
1436
1487
MAD_ARCHIVE_DEBUG (std::cout << " deserialize std::map" << std::endl);
1488
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1489
+ Alloc allocator;
1490
+ ar & allocator;
1491
+ t = std::map<T,Q,Compare,Alloc>(allocator);
1492
+ }
1493
+ else
1494
+ t.clear ();
1437
1495
std::size_t n = 0 ;
1438
1496
ar & n;
1439
1497
while (n--) {
1440
1498
std::pair<T,Q> p;
1441
1499
ar & p;
1442
- t[ p.first ] = p.second ;
1500
+ t. emplace ( std::move ( p.first ), std::move ( p.second )) ;
1443
1501
}
1444
1502
}
1445
1503
};
@@ -1460,6 +1518,9 @@ namespace madness {
1460
1518
// / \param[in] s The \c set.
1461
1519
static inline void store (const Archive& ar, const std::set<T, Compare, Alloc>& s) {
1462
1520
MAD_ARCHIVE_DEBUG (std::cout << " serialize std::set" << std::endl);
1521
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1522
+ ar & s.get_allocator ();
1523
+ }
1463
1524
ar << s.size ();
1464
1525
for (const auto &i : s)
1465
1526
ar << i;
@@ -1481,6 +1542,11 @@ namespace madness {
1481
1542
// / \param[out] s The \c set.
1482
1543
static void load (const Archive& ar, std::set<T, Compare, Alloc>& s) {
1483
1544
MAD_ARCHIVE_DEBUG (std::cout << " deserialize std::set" << std::endl);
1545
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1546
+ Alloc allocator;
1547
+ ar & allocator;
1548
+ s = std::set<T, Compare, Alloc>(allocator);
1549
+ }
1484
1550
std::size_t size;
1485
1551
ar >> size;
1486
1552
s.clear ();
@@ -1510,6 +1576,9 @@ namespace madness {
1510
1576
// / \param[in] s The \c list.
1511
1577
static inline void store (const Archive& ar, const std::list<T, Alloc>& s) {
1512
1578
MAD_ARCHIVE_DEBUG (std::cout << " serialize std::list" << std::endl);
1579
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1580
+ ar & s.get_allocator ();
1581
+ }
1513
1582
ar << s.size ();
1514
1583
for (const auto &i : s)
1515
1584
ar << i;
@@ -1530,6 +1599,11 @@ namespace madness {
1530
1599
// / \param[out] s The \c list.
1531
1600
static void load (const Archive& ar, std::list<T, Alloc>& s) {
1532
1601
MAD_ARCHIVE_DEBUG (std::cout << " deserialize std::list" << std::endl);
1602
+ if constexpr (!std::allocator_traits<Alloc>::is_always_equal::value) {
1603
+ Alloc allocator;
1604
+ ar & allocator;
1605
+ s = std::list<T, Alloc>(allocator);
1606
+ }
1533
1607
std::size_t size;
1534
1608
ar >> size;
1535
1609
s.clear ();
0 commit comments