Skip to content

Propose for inplace construct from Fusion Sequence #217

Description

@correaa

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions