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

Provide a substitute to BOOST_FUSION_ADAPT_STRUCT_xxx macros #181

Open
gnzlbg opened this issue Sep 18, 2015 · 3 comments
Open

Provide a substitute to BOOST_FUSION_ADAPT_STRUCT_xxx macros #181

gnzlbg opened this issue Sep 18, 2015 · 3 comments
Labels

Comments

@gnzlbg
Copy link

gnzlbg commented Sep 18, 2015

Would it be possible to provide a substitute for BOOST_FUSION_ADAPT_STRUCT_xxx macros to be able to use classes and structs as heterogeneous (+associative?) sequences?

I don't know if there are any C++>=11 features that would allow improving these macros or designing a new/better version of them, but that might be worth looking into.

@ldionne
Copy link
Member

ldionne commented Sep 19, 2015

The initial idea was that user-defined types were models of the Struct concept, not some kind of heterogeneous sequence themselves. However, one could convert any Struct to a heterogeneous sequence or a map with e.g. to<tuple_tag>(user_defined_type) or to<map_tag>(user_defined_type). Unfortunately, this currently requires copying the members of the user defined type, so you can't e.g. modify the members of the struct in place as-if they were a sequence right now. That problem should be resolved with issue #175.

Do you see another reason to allow seeing a user defined type as an heterogeneous sequence directly, rather than using the intermediate Struct concept? The advantage of the Struct concept over seeing a UDT directly as a map is that Structs specify the order of their members to be the same as inside the UDT's definition, whereas a map does not enforce any ordering.

@ldionne
Copy link
Member

ldionne commented Oct 26, 2015

@gnzlbg ping

@gnzlbg
Copy link
Author

gnzlbg commented Oct 26, 2015

The advantage of the Struct concept over seeing a UDT directly as a map is that Structs specify the order of their members to be the same as inside the UDT's definition, whereas a map does not enforce any ordering.

I think that is a pretty important advantage that might turn out to be very useful for serialization (and thus worth the trouble, but see below).

Unfortunately, this currently requires copying the members of the user defined type, so you can't e.g. modify the members of the struct in place as-if they were a sequence right now. That problem should be resolved with issue #175.

That wouldn't really be acceptable but it seems that it would only be temporary and that there is a plan to fix it.

Do you see another reason to allow seeing a user defined type as an heterogeneous sequence directly, rather than using the intermediate Struct concept?

IIUC one will be able to create an intermediate model of Struct with value/&/const&/&& semantics from an UDT. Heterogeneous algorithms would work on the intermediate model of Struct, and allow &/const&/&& access to the struct. Is that what you have in mind?

If so, I don't see any reason to allow seeing an user defined type as an heterogeneous sequence (one can just write non-member non-friends functions that "adapt" the UDT as a model of Struct by returning an intermediate type).

I've tried to stretch my imagination but even in the hypothetical case that types might ever be able to use heterogeneous algorithms "on themselves", then they will probably also be able to adapt themselves as a model of Struct and work on that. So I am not really able to find an use case where allowing an user defined type to be an heterogeneous would be required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants