From e6ba37cdd4fbc5529d4a2515a33712a03381ba9a Mon Sep 17 00:00:00 2001 From: Arnaud Becheler <8360330+Becheler@users.noreply.github.com> Date: Mon, 20 Jul 2026 10:43:42 +0200 Subject: [PATCH] refactor: decouple serialization --- include/boost/graph/adj_list_serialize.hpp | 46 ++++++++++---------- include/boost/pending/property_serialize.hpp | 12 +++-- test/serialize.cpp | 5 +++ 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/include/boost/graph/adj_list_serialize.hpp b/include/boost/graph/adj_list_serialize.hpp index c9abfb32c..c1bdeebf9 100644 --- a/include/boost/graph/adj_list_serialize.hpp +++ b/include/boost/graph/adj_list_serialize.hpp @@ -17,9 +17,8 @@ #include #include -#include -#include -#include +#include +#include namespace boost { @@ -29,13 +28,16 @@ namespace serialization // Turn off tracking for adjacency_list. It's not polymorphic, and we // need to do this to enable saving of non-const adjacency lists. + // Specializing tracking_level_impl (not tracking_level) avoids including + // . boost::integral_constant carries the + // integral_c_tag the archive expects. + template < class T > struct tracking_level_impl; template < class OEL, class VL, class D, class VP, class EP, class GP, class EL > - struct tracking_level< boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL > > + struct tracking_level_impl< + const boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL > > + : boost::integral_constant< int, 0 /* track_never */ > { - typedef mpl::integral_c_tag tag; - typedef mpl::int_< track_never > type; - BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value); }; template < class Archive, class OEL, class VL, class D, class VP, class EP, @@ -50,8 +52,8 @@ namespace serialization const auto V = num_vertices(graph); const auto E = num_edges(graph); - ar << BOOST_SERIALIZATION_NVP(V); - ar << BOOST_SERIALIZATION_NVP(E); + ar << BOOST_NVP(V); + ar << BOOST_NVP(E); // assign indices to vertices std::unordered_map< Vertex, Vertex > indices(V); @@ -59,20 +61,20 @@ namespace serialization BGL_FORALL_VERTICES_T(v, graph, Graph) { indices[v] = num++; - ar << serialization::make_nvp( + ar << boost::make_nvp( "vertex_property", get(vertex_all_t(), graph, v)); } // write edges BGL_FORALL_EDGES_T(e, graph, Graph) { - ar << serialization::make_nvp("u", indices[source(e, graph)]); - ar << serialization::make_nvp("v", indices[target(e, graph)]); - ar << serialization::make_nvp( + ar << boost::make_nvp("u", indices[source(e, graph)]); + ar << boost::make_nvp("v", indices[target(e, graph)]); + ar << boost::make_nvp( "edge_property", get(edge_all_t(), graph, e)); } - ar << serialization::make_nvp( + ar << boost::make_nvp( "graph_property", get_property(graph, graph_all_t())); } @@ -89,10 +91,10 @@ namespace serialization using VertexSizeType = typename graph_traits< Graph >::vertices_size_type; VertexSizeType V; - ar >> BOOST_SERIALIZATION_NVP(V); + ar >> BOOST_NVP(V); VertexSizeType E; - ar >> BOOST_SERIALIZATION_NVP(E); + ar >> BOOST_NVP(E); std::vector< Vertex > verts(V); size_t i = 0; @@ -100,7 +102,7 @@ namespace serialization { const auto v = add_vertex(graph); verts[i++] = v; - ar >> serialization::make_nvp( + ar >> boost::make_nvp( "vertex_property", get(vertex_all_t(), graph, v)); } @@ -108,16 +110,16 @@ namespace serialization { Vertex u; Vertex v; - ar >> BOOST_SERIALIZATION_NVP(u); - ar >> BOOST_SERIALIZATION_NVP(v); + ar >> BOOST_NVP(u); + ar >> BOOST_NVP(v); Edge e; bool inserted; boost::tie(e, inserted) = add_edge(verts[u], verts[v], graph); - ar >> serialization::make_nvp( + ar >> boost::make_nvp( "edge_property", get(edge_all_t(), graph, e)); } - ar >> serialization::make_nvp( + ar >> boost::make_nvp( "graph_property", get_property(graph, graph_all_t())); } @@ -127,7 +129,7 @@ namespace serialization boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL >& graph, const unsigned int file_version) { - boost::serialization::split_free(ar, graph, file_version); + boost::core::split_free(ar, graph, file_version); } } // serialization diff --git a/include/boost/pending/property_serialize.hpp b/include/boost/pending/property_serialize.hpp index cbdc163a4..56c08c657 100644 --- a/include/boost/pending/property_serialize.hpp +++ b/include/boost/pending/property_serialize.hpp @@ -7,9 +7,13 @@ #define BOOST_PROPERTY_SERIALIZE_HPP #include +#include + +// Only the Parallel BGL (MPI) specializations below need Boost.Serialization, +// so keep its header out of the default build. +#ifdef BOOST_GRAPH_USE_MPI #include -#include -#include +#endif namespace boost { @@ -22,8 +26,8 @@ template < class Archive, class Tag, class T, class Base > void serialize( Archive& ar, property< Tag, T, Base >& prop, const unsigned int /*version*/) { - ar& serialization::make_nvp("property_value", prop.m_value); - ar& serialization::make_nvp("property_base", prop.m_base); + ar& boost::make_nvp("property_value", prop.m_value); + ar& boost::make_nvp("property_base", prop.m_base); } #ifdef BOOST_GRAPH_USE_MPI diff --git a/test/serialize.cpp b/test/serialize.cpp index a6044c414..b609238d6 100644 --- a/test/serialize.cpp +++ b/test/serialize.cpp @@ -16,6 +16,7 @@ #include #include #include +#include struct vertex_properties { @@ -47,6 +48,10 @@ typedef adjacency_list< vecS, vecS, undirectedS, vertex_properties, typedef graph_traits< Graph >::vertex_descriptor vd_type; +static_assert(boost::serialization::tracking_level< Graph >::value + == boost::serialization::track_never, + "adjacency_list tracking_level must be track_never"); + typedef adjacency_list< vecS, vecS, undirectedS, vertex_properties > Graph_no_edge_property;