-
Notifications
You must be signed in to change notification settings - Fork 67
Open
Description
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?
Metadata
Metadata
Assignees
Labels
No labels