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

Propose for inplace construct from Fusion Sequence #217

Open
correaa opened this issue Dec 5, 2019 · 0 comments
Open

Propose for inplace construct from Fusion Sequence #217

correaa opened this issue Dec 5, 2019 · 0 comments

Comments

@correaa
Copy link
Contributor

correaa commented Dec 5, 2019

While defining semantic actions in Spirit X3, if find myself doing this a lot:

[](auto&& ctx){_val(ctx)=fusion::invoke([](auto const&... x){return MyType<U>{x...};}, _attr(ctx));}

That is to "invoke" a function just to construct an object of a type (which might or might not be the final representation assigned.)

Of course, I could fusion adapt MyType, but sometimes this is an overkill.

I think this can be condensed by a simple construct function in fusion.
For example implemented like this:

template<class T, class Seq>
auto construct(Seq&& seq){
	return invoke([](auto const&... x){return T{x...};}, seq);
}

This way the semantic action can be reduced to:

[](auto&& ctx){_val(ctx)=fusion::construct<MyType<U>>(_attr(ctx));}

The real power would be to use it in conjunction with CTAD (in c++17):

template<template<class...> class T, class Seq>
auto construct(Seq&& seq){
	return invoke([](auto const&... x){return T{x...};}, seq);
}
[](auto&& ctx){_val(ctx)=fusion::construct<MyType>(_attr(ctx));}

(fusion::construct could be called fusion::make alternatively).

Does something like this exists in Fusion already?

Would this be a useful addition to Boost.Fusion or is it too specific?

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

No branches or pull requests

1 participant