std::shared_ptr works with pointer tracking
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <cereal/binary_archive/binary_archive.hpp>
|
||||
#include <cereal/binary_archive/string.hpp>
|
||||
#include <cereal/json_archive/json_archive.hpp>
|
||||
#include <cereal/binary_archive/shared_ptr.hpp>
|
||||
|
||||
#include <cxxabi.h>
|
||||
#include <sstream>
|
||||
@@ -135,12 +136,44 @@ int main()
|
||||
|
||||
assert(e_in == e_out);
|
||||
|
||||
cereal::JSONOutputArchive json(std::cout);
|
||||
//cereal::JSONOutputArchive json(std::cout);
|
||||
|
||||
std::string hello = "Hello, World!";
|
||||
json & CEREAL_NVP(hello);
|
||||
//std::string hello = "Hello, World!";
|
||||
//json & CEREAL_NVP(hello);
|
||||
//json & CEREAL_NVP(e_out); <<< Need to figure out how to recurse!
|
||||
//
|
||||
|
||||
{
|
||||
std::ofstream os("ptr.txt");
|
||||
cereal::BinaryOutputArchive archive(os);
|
||||
std::shared_ptr<int> xptr1 = std::make_shared<int>(5);
|
||||
std::shared_ptr<int> xptr2 = xptr1;
|
||||
std::shared_ptr<int> yptr1 = std::make_shared<int>(6);
|
||||
std::shared_ptr<int> yptr2 = yptr1;
|
||||
archive & xptr1;
|
||||
archive & xptr2;
|
||||
archive & yptr1;
|
||||
archive & yptr2;
|
||||
|
||||
}
|
||||
{
|
||||
std::ifstream is("ptr.txt");
|
||||
cereal::BinaryInputArchive archive(is);
|
||||
std::shared_ptr<int> xptr1;
|
||||
std::shared_ptr<int> xptr2;
|
||||
std::shared_ptr<int> yptr1;
|
||||
std::shared_ptr<int> yptr2;
|
||||
archive & xptr1;
|
||||
archive & xptr2;
|
||||
archive & yptr1;
|
||||
archive & yptr2;
|
||||
|
||||
assert(xptr1.get() == xptr2.get());
|
||||
assert(yptr1.get() == yptr2.get());
|
||||
std::cout << *xptr1 << " " << *xptr2 << std::endl;
|
||||
std::cout << *yptr1 << " " << *yptr2 << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user