Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ aggregates initialization with c-style arrays

In c++14 I have the following type:

std::tuple<int[2], int>;

How can I properly initialize it? This

std::tuple<int[2], int> a {{2,2},3};

gives me this error:

/usr/include/c++/5/tuple:108:25: error: array used as initializer

While this:

std::tuple<std::array<int,2>, int> a {{2,2},3};

works, but I want to be able to work with standard C-style arrays

like image 862
Mario Demontis Avatar asked Mar 05 '23 15:03

Mario Demontis


1 Answers

std::tuple is not an aggregate and doesn't provide a list-initializer constructor. This makes list initialization with that type impossible to use with C-arrays.

You can however use std::make_tuple:

auto a = std::make_tuple<int[2], int>({2,2},3);
like image 151
YSC Avatar answered Mar 17 '23 10:03

YSC