C++ Logo

std-discussion

Advanced search

Re: List initialize from tuple

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sat, 13 Feb 2021 10:01:58 +0200
On Sat, 13 Feb 2021 at 09:50, Jefferson Carpenter via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Hey, I just had some code that I wanted to write where I list initialize
> a struct from a tuple.
>
> Of course C++ has std::make_from_tuple, but this uses direct
> initialization. That is
>
> struct Foo {
> int a;
> int b;
> };
>
> cannot be initialized using std::make_from_tuple<Foo, std::tuple<int, int>>.

In C++20, doing make_from_tuple<X> works out of the box:
https://wandbox.org/permlink/qlByUwVZlmLRgsZ3

because C++20 has https://wg21.link/p0960

You're welcome. :)

Received on 2021-02-13 02:02:12