Skip to content

Instantly share code, notes, and snippets.

@sithhell
Created January 8, 2018 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sithhell/01e605759cef39b707d107e54b738ac3 to your computer and use it in GitHub Desktop.
Save sithhell/01e605759cef39b707d107e54b738ac3 to your computer and use it in GitHub Desktop.
struct A
{
A(int ii)
: i(ii)
{}
// load from archive...
template <typename Archive>
A(serialization::load<Archive, A>& l)
: i(serialization::load<Archive, int>(l))
{}
// save to archive...
template <typename Archive>
operator serialization::save<Archive>() const
{
return serialization::save<Archive>(i);
}
int i;
};
struct B
{
B() : a(80) {};
B(int i) : a(i) {};
// load from archive...
template <typename Archive>
explicit B(serialization::load<Archive, B>& l)
: a(serialization::load<Archive, A>(l))
{}
// save to archive...
template <typename Archive>
operator serialization::save<Archive>() const
{
return serialization::save<Archive>(a);
}
A a;
};
// Non-intrusive
template <typename T>
struct C
{
B b;
};
namespace serialization {
template <typename T>
struct serialization_traits<C<T>>
{
// load from archive...
template <typename Archive>
static C<T> load(serialization::load<Archive, C<T>>& l)
{
return C<T>{serialization::load<Archive, B>(l)};
}
// save to archive...
template <typename Archive>
static serialization::save<Archive> save(C<T> const& c)
{
return serialization::save<Archive>(c.b);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment