1// (C) Copyright 2009 Brian Ravnsgaard and Kenneth Riddile
2// Use, modification and distribution are subject to the
3// Boost Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org for most recent version including documentation.
7
8// Test that serialization of std::bitset works.
9// Should pass compilation and execution
10// 16.09.2004, updated 04.03.2009
11
12#include <cstddef> // NULL
13#include <cstdio> // remove
14#include <fstream>
15
16#include <boost/config.hpp>
17
18#if defined( BOOST_NO_STDC_NAMESPACE )
19namespace std
20{
21 using ::remove;
22}
23#endif
24
25#include "test_tools.hpp"
26
27#include <boost/serialization/bitset.hpp>
28#include <boost/serialization/nvp.hpp>
29
30int test_main( int /* argc */, char* /* argv */[] )
31{
32 const char* testfile = boost::archive::tmpnam( NULL );
33 BOOST_REQUIRE( NULL != testfile );
34
35 std::bitset<8> bitsetA;
36 bitsetA.set( position: 0, val: false );
37 bitsetA.set( position: 1, val: true );
38 bitsetA.set( position: 2, val: false );
39 bitsetA.set( position: 3, val: true );
40 bitsetA.set( position: 4, val: false );
41 bitsetA.set( position: 5, val: false );
42 bitsetA.set( position: 6, val: true );
43 bitsetA.set( position: 7, val: true );
44
45 {
46 test_ostream os( testfile, TEST_STREAM_FLAGS );
47 test_oarchive oa( os );
48 oa << boost::serialization::make_nvp( n: "bitset", v&: bitsetA );
49 }
50
51 std::bitset<8> bitsetB;
52 {
53 test_istream is( testfile, TEST_STREAM_FLAGS );
54 test_iarchive ia( is );
55 ia >> boost::serialization::make_nvp( n: "bitset", v&: bitsetB );
56 }
57
58 BOOST_CHECK( bitsetA == bitsetB );
59
60 std::remove( filename: testfile );
61 return EXIT_SUCCESS;
62}
63
64// EOF
65

source code of boost/libs/serialization/test/test_bitset.cpp