11 #include "daw/daw_tuple_forward.h"
14 #include <daw/daw_attributes.h>
15 #include <daw/daw_consteval.h>
17 #include <boost/pfr.hpp>
18 #include <daw/stdinc/tuple_traits.h>
19 #include <type_traits>
26 requires( std::is_aggregate_v<T> and std::is_class_v<T> and
27 not std::is_empty_v<T> )
28 inline constexpr
bool use_boost_pfr =
false;
30 namespace pfr_details {
31 template<
typename T, std::
size_t Idx>
32 DAW_CONSTEVAL
auto get_member_name( ) {
33 constexpr
auto name = boost::pfr::get_name<Idx, T>( );
34 static_assert( not name.empty( ) );
35 return json_name<name.size( ) + 1>(
36 name.data( ), std::make_index_sequence<name.size( ) + 1>{ } );
39 template<
typename,
typename>
40 struct make_data_contract;
42 template<
typename T, std::size_t... Is>
43 struct make_data_contract<T,
std::index_sequence<Is...>> {
45 using member_types = DAW_TYPEOF(
46 boost::pfr::structure_to_tuple( std::declval<T const &>( ) ) );
51 std::tuple_element_t<Is, member_types>>...>;
53 DAW_ATTRIB_INLINE
static constexpr
auto to_json_data( T
const &value ) {
54 return boost::pfr::structure_tie( value );
62 : pfr_details::make_data_contract<
63 T, std::make_index_sequence<boost::pfr::tuple_size_v<T>>> {};
Customization point traits.
requires(std::is_aggregate_v< T > and std::is_class_v< T > and not std::is_empty_v< T >) inline const expr bool use_boost_pfr
Enable Boost PFR mappings for a type.
Mapping class for JSON data structures to C++. It must be specialized in order to parse to a user cla...