Category : aggregate-initialization

I want to make my own struct for a 3×3 Matrix. I want to allow construction via components/elements or by "rows". So either you provide a std::array<float, 9> or a std::array<std::array<float, 3>, 3> However when defining the struct like this with the following constructors: struct Matrix3x3 { Matrix3x3(std::array<float, 9> components) { } Matrix3x3(std::array<std::array<float, 3>, 3> ..

Read more

I want to make my own struct for a 3×3 Matrix. I want to allow construction via components/elements or by "rows". So either you provide a std::array<float, 9> or a std::array<std::array<float, 3>, 3> However when defining the struct like this with the following constructors: struct Matrix3x3 { Matrix3x3(std::array<float, 9> components) { } Matrix3x3(std::array<std::array<float, 3>, 3> ..

Read more

See this example: https://godbolt.org/z/5PqYWP How come this array of pairs can’t be initialized in the same way as a vector of pairs? #include <vector> #include <array> int main() { std::vector<std::pair<int,int>> v{{1,2},{3,4},{5,6}}; // succeeds std::array <std::pair<int,int>, 3> a{{1,2},{3,4},{5,6}}; // fails to compile } Source: Windows Que..

Read more

I was reading on template deduction then tried to create one. as follows:- #include <iostream> #include <array> using namespace std; template<int i,typename A,typename… B> struct deducted{ }; //Deduction guide template<typename A,typename… B> deducted(A a,B… b)->deducted<0,A,B…>; // int main(){ deducted a={"","",""}; deducted b={0,0,0}; array c={0,0,0}; } what supprises me is the test fails with error: too ..

Read more

With C++20, it is possible to have deduction guidelines generated for an alias template (See section "Deduction for alias templates at https://en.cppreference.com/w/cpp/language/class_template_argument_deduction"). Yet, I could not make them work with aggregate initialization syntax. It looks like in this case the deduction guidelines for the alias is not generated. See this example: #include <array> template <size_t ..

Read more