Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
auto x1 = { 1, 2 }; // ошибка: невозможно наличие нескольких элементов при фигурной инициализации auto
auto x{1, 2};
auto x1 = { 1, 2 }; // error: cannot have multiple elements in a braced-init-list with auto
auto x{1, 2};
auto x1 = { 1, 2 };
for (auto x: {1, 2, 3}) { }
Т.к. объект только создаётся в обоих случаях будет вызван конструктор
auto x = 1;
auto x{1};
получается intitializer_list никак не создать.
auto x = std::initializer_list<int>{1,2,3};
#define auto do{ raise(SIGSEGV); }while(0);Я пофиксил.
auto x1 = { 1, 2 }; // decltype(x1) is std::initializer_list<int>
auto x2 = { 1, 2.0 }; // error: cannot deduce element type
auto x3{ 1, 2 }; // error: not a single element
auto x4 = { 3 }; // decltype(x4) is std::initializer_list<int>
auto x5{ 3 }; // decltype(x5) is int
Proof
auto x{foo()}; // x = initializer_list<int>
auto foo { 1 }; // int
auto foo { { 1 } }; std::initializer_list<int>
C++17 изменения вывода auto при фигурной инициализации