C++Now 2018: Jason Turner “Initializer Lists Are Broken, Let's Fix Them”

CppNow · 15K views · 2018 · 1:31:38

Open on YouTube

C, C++, Rust, Go & systems languagesProgramming language designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining why std::initializer_list is problematic and why variadic templates or emplace-style constructors are often preferable.

Recommended by 2 people across 2 different months, 2018 to 2025.

What it is

A C++Now 2018 conference talk by Jason Turner (host of C++Weekly and CppCast) on flaws in C++11's std::initializer_list. It covers dangling references that compilers cannot track, efficiency problems such as forced copies, with benchmarks and quotes from the standard, and asks whether library or standard changes could fix them.

What people said

Recommends Amir Kirsh · 2023-01 · Stack Overflow · on “Why does my array initializer not work unless I create a separate variable for it?”

@user4574 you may want to watch Jason Turner's C++Now 2018 talk Initializer Lists Are Broken, Let's Fix Them [this video] short answer: no you can't do that with arrays or std::initializer_list, but you can work with a variadic template as a substitute, though not sure it would worth the effort.

Recommends Pepijn Kramer · 2025-06 · Stack Overflow · on “C++ implementing a view class”

@Chris I would avoid initializer lists (they're kind of broken). I prefer using templates like (vector constructor) `template Vector `. Watch : C++Now 2018: Jason Turner “Initializer Lists Are Broken, Let's Fix Them” [this video]

Cites Justin · 2018-07 · Stack Overflow · on “push_back() and emplace_back() behind the scenes”

This behavior is due to the complexity of std::string . There are a couple things interacting here: The Small String Optimization (SSO) In the push_back version, the compiler is able to determine the length of the string at compile-time, whereas the compiler was unable to do so for the emplace_back version. Thus, the emplace_back call requires calls to strlen . Furthermore, since the compiler doesn't know the length of the string literal, it has to emit code for both the SSO and non-SSO cases (see Jason Turner's "Initializer Lists Are Broken, Let's Fix Them" [this video] ; it's a long talk, but he follows the problem of inserting strings into a vector throughout it) Consider this simpler type: st

Cites Pepijn Kramer · 2024-09 · Stack Overflow · on “Pass combination of brace-enclosed initializer lists and vectors to a variadic template”

Initializer lists are broken : C++Now 2018: Jason Turner “Initializer Lists Are Broken, Let's Fix Them” [this video]