-
Notifications
You must be signed in to change notification settings - Fork 167
Closed
Labels
help wantedPR with a fix would be appreciatedPR with a fix would be appreciated
Description
Description of issue
Now i'm working with Boost.Fusion extension for Boost.PFR, i decomposed it into 3 PR's and opened these PR's here: boostorg/fusion#241, here boostorg/fusion#242 and here boostorg/fusion#243.
Review is moving on, there is some wishes from reviewers(more on that later).
First, I would like to talk about such a problem like 3 PR's is too much code and the review takes too long.
I suggest to make pfr more adaptable and more friendly to adapt into other libraries(not only fusion).
Suggested solution
- To implement two functions:
boost::pfr::viewboost::pfr::view_fields
- To implement
BOOST_PFR_REGISTRATE_REFLECTABLEmacro. - To add
boost::pfr::is_reflectabletrait. Example of using trait:
struct A {};
struct B {};
struct C {};
BOOST_PFR_REGISTRATE_REFLECTABLE(A)
using boost::pfr::is_reflectable;
is_reflectable<A>::value; //< true
is_reflectable<decltype(boost::pfr::view_fields(B{}))>::value; //< true
is_reflectable<C>::value; //< false
- To use
boost::pfr::is_reflectabletrait for create overloading of compare/io operators and specialization ofstd::hashfunction. Examples of using these overloads:
#include <boost/pfr/ops.hpp>
template <class T>
struct uniform_comparator_less {
bool operator()(const T& lhs, const T& rhs) const noexcept {
// If T has operator< or conversion operator then it is used.
return boost::pfr::view(lhs) < boost::pfr::view(rhs);
}
};
#include <boost/pfr/functions_for.hpp>
struct pair_like {
int first;
short second;
};
BOOST_PFR_REGISTRATE_REFLECTABLE(pair_like) // Added pair_like's specialization for is_reflectable trait.
// ...
assert(pair_like{1, 2} < pair_like{1, 3});
#include <boost/pfr/io_fields.hpp>
struct pair_like {
int first;
std::string second;
};
inline std::ostream& operator<<(std::ostream& os, const pair_like& x) {
return os << bost::pfr::view_fields(x);
}
- To declare
io,eq,ne,lt,gt,le,ge,hash_value,io_fields,eq_fields,ne_fields,lt_fields,gt_fields,le_fields,ge_fields,hash_fields,BOOST_PFR_FUNCTIONS_FORas deprecated, and to actualize https://www.boost.org/doc/libs/1_75_0/doc/html/boost_pfr/tutorial.html#boost_pfr.tutorial.three_ways_of_getting_operators.
Conclusion
If everything planned can be done, then the PFR will be adapted as easily as the std::tuple, it will be just one small PR.
Metadata
Metadata
Assignees
Labels
help wantedPR with a fix would be appreciatedPR with a fix would be appreciated