pfr icon indicating copy to clipboard operation
pfr copied to clipboard

`BOOST_PFR_FUNCTIONS_FOR` doesn't nest

Open u3shit opened this issue 3 years ago • 0 comments

I don't know if this is a bug or feature, but BOOST_PFR_FUNCTIONS_FOR requires structure members to have an std::hash specialization, but it doesn't itself provide one, so the following example fails to compile:

#include <boost/pfr/functions_for.hpp>

struct A { int a; };
BOOST_PFR_FUNCTIONS_FOR(A);
// namespace std { template<> struct hash<A> { size_t operator()(A); }; }

struct B { A a; };
BOOST_PFR_FUNCTIONS_FOR(B);

Godbolt

Uncommenting the hash specialization will make this code compile, but it's bothersome to do this for every type that just needs some comparison and print operations. Would it be possible to have a BOOST_PFR_FUNCTIONS_FOR version that doesn't try to generate a hash function? (Especially that it generates a hash_value function that is only compatible with boost containers, not an std::hash specialization that is a more compatible solution with C++11 or later.) Or at least make hash_fields compatible with hash_value?

u3shit avatar Jul 31 '21 18:07 u3shit