stdinitializerlist Questions

2

The following program compiles without warnings in GCC and Clang and produces the expected output: #include <initializer_list> #include <iostream> constexpr std::initializer_list<st...
Hijacker asked 26/10, 2022 at 14:1

1

I can concisely (with braces) initialize 5 out of 6 of the following cases: of copyable of move-only array YES YES std::array YES YES std::vector YES NO The one case that doe...
Fabri asked 14/8, 2023 at 7:6

1

Solved

According to cppreference.com, std::initializer_lists have constexpr constructors and constexpr size methods (since C++14). Although the compiler I was using seemed to agree that the size of a cons...
Ergocalciferol asked 21/7, 2023 at 17:45

4

Solved

I understand from here that std::initializer_list doesn't need to allocate heap memory. Which is very strange to me since you can take in an std::initializer_list object without specifying the size...
Stylite asked 25/5, 2022 at 12:7

1

The suggested implementation of std::initializer_list in the standard and The C++ Programming Language are simple. By simple I mean there is nothing strange. But things become complex in the Compil...
Differentiate asked 11/8, 2021 at 13:56

1

From [dcl.init.list] The template std​::​initializer_­list is not predefined; if the header <initializer_­list> is not included prior to a use of std​::​initializer_­list — even an implicit ...
Bookmobile asked 19/3, 2018 at 17:29

1

Solved

First of all this is curiosity kind of question, I would never write code like this in real life. Following code behaves differently with -O3 -std=c++14 and -O3 -std=c++17 flags, in C++14 I get ba...
Twombly asked 17/12, 2019 at 18:36

2

Solved

I would like to "materialize" a variadic types list into an initializer_list of related values. For example, having an std::tuple of several std::integral_constant<T, x> get an std::initializ...
Islamite asked 11/9, 2018 at 6:22

3

Solved

i have a std::vector<std::vector<double>> and would like to add some elements at the end of it so this was my trial: std::vector<std::vector<double> > vec; vec.emplace_back(...
Persuade asked 3/7, 2014 at 10:14

3

Solved

I know, that I can initialize data like this. int array[3] = { 1, 2, 3 }; or even int array[2][2] = { {1, 2}, {3, 4} }; I can also do it with std::vector std::vector<int> A = { 1, 2, 3...
Rachellerachis asked 23/5, 2018 at 13:7

2

Solved

In code like this: #include <iostream> #include <initializer_list> #include <string> struct A { A() { std::cout << "2" << std::endl; } A(int a) { std::cout <&...
Cuttle asked 29/1, 2018 at 8:5

2

I've tried the C++0x initializer-list implementation of my G++ version but it outputs only empty lines. #include <initializer_list> #include <iostream> #include <string> int ma...
Queasy asked 9/4, 2011 at 13:41

1

Solved

I'm wondering whether the tuple can be initialized by initializer list (to be more precise - by initializer_list of initializer_lists)? Considering the tuple definition: typedef std::tuple< std...
1

© 2022 - 2024 — McMap. All rights reserved.