Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / histogram / unlimited_storage.hpp
index bce1098..abedef7 100644 (file)
 
 #include <algorithm>
 #include <boost/assert.hpp>
+#include <boost/config.hpp>
 #include <boost/core/alloc_construct.hpp>
 #include <boost/core/exchange.hpp>
+#include <boost/core/nvp.hpp>
+#include <boost/histogram/detail/array_wrapper.hpp>
 #include <boost/histogram/detail/iterator_adaptor.hpp>
 #include <boost/histogram/detail/large_int.hpp>
 #include <boost/histogram/detail/operators.hpp>
 #include <boost/histogram/detail/safe_comparison.hpp>
-#include <boost/histogram/detail/static_if.hpp>
 #include <boost/histogram/fwd.hpp>
 #include <boost/mp11/algorithm.hpp>
 #include <boost/mp11/list.hpp>
@@ -442,10 +444,15 @@ public:
     constexpr auto ti = buffer_type::template type_index<V>();
     constexpr auto nt = mp11::mp_size<typename buffer_type::types>::value;
     const std::size_t size = static_cast<std::size_t>(std::distance(s_begin, s_end));
-    detail::static_if_c<(ti < nt)>(
-        [this, &size, &s_begin](auto) { buffer_.template make<V>(size, s_begin); },
-        [this, &size, &s_begin](auto) { buffer_.template make<double>(size, s_begin); },
-        0);
+#ifdef BOOST_NO_CXX17_IF_CONSTEXPR
+    if
+#else
+    if constexpr
+#endif
+        (ti < nt)
+      buffer_.template make<V>(size, s_begin);
+    else
+      buffer_.template make<double>(size, s_begin);
   }
 
   template <class Iterable, class = detail::requires_iterable<Iterable>>
@@ -498,6 +505,28 @@ public:
     buffer_.template make<T>(s, p);
   }
 
+  template <class Archive>
+  void serialize(Archive& ar, unsigned /* version */) {
+    if (Archive::is_loading::value) {
+      buffer_type tmp(buffer_.alloc);
+      std::size_t size;
+      ar& make_nvp("type", tmp.type);
+      ar& make_nvp("size", size);
+      tmp.visit([this, size](auto* tp) {
+        BOOST_ASSERT(tp == nullptr);
+        using T = std::decay_t<decltype(*tp)>;
+        buffer_.template make<T>(size);
+      });
+    } else {
+      ar& make_nvp("type", buffer_.type);
+      ar& make_nvp("size", buffer_.size);
+    }
+    buffer_.visit([this, &ar](auto* tp) {
+      auto w = detail::make_array_wrapper(tp, this->buffer_.size);
+      ar& make_nvp("buffer", w);
+    });
+  }
+
 private:
   struct incrementor {
     template <class T>