cereal
cereal copied to clipboard
non-member checks only consider related namespaces, not local ones
If the load/save functions are provided in the current namespace or the global namespace they are not picked up by the respective checks, i.e. MACROs make the whole thing fail, commenting them out, makes it work.
Here's a minimal example:
#include <cereal/details/traits.hpp>
#include <cereal/archives/binary.hpp>
#include <fstream>
namespace foo
{
struct S
{
int i;
};
} // namespace end
template <typename archive_t>
int save_minimal(archive_t &&, typename foo::S s)
{
return s.i;
}
template <typename archive_t>
void load_minimal(archive_t &&, typename foo::S & out, int in)
{
out.i = in;
}
// if you move the namespace end here, it works.
int main()
{
typename foo::S s;
s.i = 8;
std::ofstream os{"test", std::ios::binary};
cereal::BinaryOutputArchive oarchive{os};
oarchive(s);
}
In general the traits checks seems to be causing a huge amount of issues. Is there a reason this approach was chosen over an approach based on enable_if?
I could not make cereal work with a non-member check outside the serialised type's namespace either, however it looks like your snippet is missing a const on typename foo::S s in save_minimal