cereal icon indicating copy to clipboard operation
cereal copied to clipboard

non-member checks only consider related namespaces, not local ones

Open h-2 opened this issue 6 years ago • 1 comments

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?

h-2 avatar Apr 30 '19 14:04 h-2

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

Stepland avatar Mar 02 '20 12:03 Stepland