C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Making tuple an aggregate

From: Hui Xie <hui.xie1990_at_[hidden]>
Date: Tue, 7 Jun 2022 21:58:12 +0100
As others mentioned we can't make it aggregate because of all of the
constructors. piecewise_construct is definitely a nice thing to have. With
today's available constructors, you could use the (UTypes&&...) constructor
to construct the tuple<NonMovable>.

template <class Fn>
struct wrapper{
Fn fn_;
operator std::invoke_result_t<Fn>() const{
return fn_();
}
};

template <class Fn>
wrapper(Fn) -> wrapper<Fn>;

void f() {
std::tuple<NonMoveable,NonMoveable> t{
wrapper{[]{return NonMoveable{1,2};}},
wrapper{[]{return NonMoveable{3,4};}}
};
}

https://godbolt.org/z/j385snTeT

Yes it is very awkward to write this just to construct a tuple.



On Tue, Jun 7, 2022 at 9:14 PM Lénárd Szolnoki via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Never mind, just checked the available tuple constructors...
>
> On 7 June 2022 21:11:42 BST, "Lénárd Szolnoki via Std-Proposals" <
> std-proposals_at_[hidden]> wrote:
>>
>> Hi,
>>
>> What breaks by making tuple an aggregate? Would it affect ABI?
>>
>> There was a good point about EBO, and I think neither `Ts... ts;` nor
>> `[[no_unique_address]] Ts... ts;` would produce the same layout as current
>> tuple implementations, at least on Itanium. AFAIK current implementations
>> do make use of EBO, but they don't overlap non-empty tuple members on tail
>> padding, while [[no_unique_address]] would do that.
>>
>> Maybe it could be worked around with `[[no_unique_address]]
>> wrapper<Ts>... ts;`, but then initialization with brace-elision can become
>> awkward (see std::array).
>>
>> Cheers,
>> Lénárd
>>
>> On 7 June 2022 20:27:45 BST, Jason McKesson via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>>
>>> There's one thought that immediately comes to mind: even if we can
>>> make parameter pack members like you want... you can't change how
>>> `std::tuple` works. It is going to have to be given a different name.
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>>> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-06-07 20:58:23