3 * \brief Provides Boost.Serialization support for std::bitset
4 * \author Brian Ravnsgaard Riis
5 * \author Kenneth Riddile
6 * \date 16.09.2004, updated 04.03.2009
7 * \copyright 2004 Brian Ravnsgaard Riis
8 * \license Boost Software License 1.0
10 #ifndef BOOST_SERIALIZATION_BITSET_HPP
11 #define BOOST_SERIALIZATION_BITSET_HPP
13 // MS compatible compilers support #pragma once
19 #include <cstddef> // size_t
21 #include <boost/config.hpp>
22 #include <boost/serialization/split_free.hpp>
23 #include <boost/serialization/string.hpp>
24 #include <boost/serialization/nvp.hpp>
27 namespace serialization{
29 template <class Archive, std::size_t size>
32 std::bitset<size> const & t,
33 const unsigned int /* version */
35 const std::string bits = t.template to_string<
36 std::string::value_type,
37 std::string::traits_type,
38 std::string::allocator_type
40 ar << BOOST_SERIALIZATION_NVP( bits );
43 template <class Archive, std::size_t size>
46 std::bitset<size> & t,
47 const unsigned int /* version */
50 ar >> BOOST_SERIALIZATION_NVP( bits );
51 t = std::bitset<size>(bits);
54 template <class Archive, std::size_t size>
55 inline void serialize(
57 std::bitset<size> & t,
58 const unsigned int version
60 boost::serialization::split_free( ar, t, version );
63 // don't track bitsets since that would trigger tracking
64 // all over the program - which probably would be a surprise.
65 // also, tracking would be hard to implement since, we're
66 // serialization a representation of the data rather than
68 template <std::size_t size>
69 struct tracking_level<std::bitset<size> >
70 : mpl::int_<track_never> {} ;
75 #endif // BOOST_SERIALIZATION_BITSET_HPP