Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visitable init #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/visit_struct/visit_struct_intrusive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,40 @@ static inline ::visit_struct::detail::Append_t<VISIT_STRUCT_GET_REGISTERED_MEMBE
Visit_Struct_Get_Visitables__(::visit_struct::detail::Rank<VISIT_STRUCT_GET_REGISTERED_MEMBERS::size + 1>); \
static_assert(true, "")

#define VISITABLE_INIT(TYPE, NAME, VALUE) \
TYPE NAME = VALUE; \
struct VISIT_STRUCT_MAKE_MEMBER_NAME(NAME) : \
visit_struct::detail::member_ptr_helper<VISIT_STRUCT_CURRENT_TYPE, \
TYPE, \
&VISIT_STRUCT_CURRENT_TYPE::NAME> \
{ \
static VISIT_STRUCT_CONSTEXPR const ::visit_struct::detail::char_array<sizeof(#NAME)> & member_name() { \
return #NAME; \
} \
}; \
static inline ::visit_struct::detail::Append_t<VISIT_STRUCT_GET_REGISTERED_MEMBERS, \
VISIT_STRUCT_MAKE_MEMBER_NAME(NAME)> \
Visit_Struct_Get_Visitables__(::visit_struct::detail::Rank<VISIT_STRUCT_GET_REGISTERED_MEMBERS::size + 1>); \
static_assert(true, "")

// use variadic macro to allow passing initializer lists with commas, e.g.:
// VISITABLE_DIRECT_INIT(std::vector<int>, foo, {1, 2, 3})
#define VISITABLE_DIRECT_INIT(TYPE, NAME, ...) \
TYPE NAME __VA_ARGS__; \
struct VISIT_STRUCT_MAKE_MEMBER_NAME(NAME) : \
visit_struct::detail::member_ptr_helper<VISIT_STRUCT_CURRENT_TYPE, \
TYPE, \
&VISIT_STRUCT_CURRENT_TYPE::NAME> \
{ \
static VISIT_STRUCT_CONSTEXPR const ::visit_struct::detail::char_array<sizeof(#NAME)> & member_name() { \
return #NAME; \
} \
}; \
static inline ::visit_struct::detail::Append_t<VISIT_STRUCT_GET_REGISTERED_MEMBERS, \
VISIT_STRUCT_MAKE_MEMBER_NAME(NAME)> \
Visit_Struct_Get_Visitables__(::visit_struct::detail::Rank<VISIT_STRUCT_GET_REGISTERED_MEMBERS::size + 1>); \
static_assert(true, "")

#define END_VISITABLES \
typedef VISIT_STRUCT_GET_REGISTERED_MEMBERS Visit_Struct_Registered_Members_List__; \
typedef ::visit_struct::detail::intrusive_tag Visit_Struct_Visitable_Structure_Tag__; \
Expand Down