test_private_ctor.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. // test_private_ctor.cpp
  3. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <sstream>
  8. #include "test_tools.hpp"
  9. #include <boost/serialization/vector.hpp>
  10. #include <boost/archive/text_iarchive.hpp>
  11. #include <boost/archive/text_oarchive.hpp>
  12. class V {
  13. private:
  14. friend int test_main(int /* argc */, char * /* argv */[]);
  15. friend class boost::serialization::access;
  16. int m_i;
  17. V() :
  18. m_i(0)
  19. {}
  20. template<class Archive>
  21. void serialize(Archive& ar, unsigned /*version*/)
  22. {
  23. ar & m_i;
  24. }
  25. public:
  26. ~V(){}
  27. bool operator==(const V & v) const {
  28. return m_i == v.m_i;
  29. }
  30. };
  31. int test_main(int /* argc */, char * /* argv */[])
  32. {
  33. std::stringstream ss;
  34. const V v;
  35. {
  36. boost::archive::text_oarchive oa(ss);
  37. oa << v;
  38. }
  39. V v1;
  40. {
  41. boost::archive::text_iarchive ia(ss);
  42. ia >> v1;
  43. }
  44. BOOST_CHECK(v == v1);
  45. const V *vptr = & v;
  46. {
  47. boost::archive::text_oarchive oa(ss);
  48. oa << vptr;
  49. }
  50. V *vptr1;
  51. {
  52. boost::archive::text_iarchive ia(ss);
  53. ia >> vptr1;
  54. }
  55. BOOST_CHECK(*vptr == *vptr1);
  56. return EXIT_SUCCESS;
  57. }