Propose for inplace construct from Fusion Sequence
- Dominant language
- C++
- Stars
- 50
- Forks
- 68
- PR merge metrics
- No merged PRs in 30d
Description
While defining semantic actions in Spirit X3, if find myself doing this a lot:
```c++
[](auto&& ctx){_val(ctx)=fusion::invoke([](auto const&... x){return MyType{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:
```c++
template
auto construct(Seq&& seq){
return invoke([](auto const&... x){return T{x...};}, seq);
}
```
This way the semantic action can be reduced to:
```c++
[](auto&& ctx){_val(ctx)=fusion::construct>(_attr(ctx));}
```
The real power would be to use it in conjunction with CTAD (in c++17):
```c++
template class T, class Seq>
auto construct(Seq&& seq){
return invoke([](auto const&... x){return T{x...};}, seq);
}
```
```c++
[](auto&& ctx){_val(ctx)=fusion::construct(_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?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.