what belongs in the standard library?
TRANSCRIPT
Bryce Adelstein Lelbach
@blelbach
HPC Programming Models Architect
Standard C++ Library Evolution Chair, US Programming Languages Chair
WHAT BELONGS IN
THE STANDARD LIBRARY?
What Has Made C++ Successful?Performance?
9Copyright (C) 2021 Bryce Adelstein Lelbach
Source: The Computer Language Benchmark Game
What Has Made C++ Successful?UNIVERSALITY
15Copyright (C) 2021 Bryce Adelstein Lelbach
AnyProblem
HPC
Gaming
Robotics
Finance
Apps
Vehicles
What Has Made C++ Successful?UNIVERSALITY
16Copyright (C) 2021 Bryce Adelstein Lelbach
AnyProblem
AnyParadigm
HPC
Gaming
Robotics
Finance
Apps
Vehicles
Imperative
Functional
Parallel
Object Oriented
Generic
Reactive
What Has Made C++ Successful?UNIVERSALITY
17Copyright (C) 2021 Bryce Adelstein Lelbach
Any Platform
AnyProblem
AnyParadigm
HPC
Gaming
Robotics
Finance
Apps
Vehicles
Imperative
Functional
Parallel
Object Oriented
Generic
Reactive
Our Individual Perception
18Copyright (C) 2021 Bryce Adelstein Lelbach
Pleasestandardizesomething
in this space.
Acceptable
Solutions
Reality
19Copyright (C) 2021 Bryce Adelstein Lelbach
Acceptable Solutions(for Domain B)
Acceptable Solutions(for Domain C)
Acceptable
Solutions(for Domain A)
Acceptable
Solutions(for Domain D)
Use Case Sympathy (noun)
use case sym·pa·thy | yüz kās sim-pə-thē
Accepting the importance and
validity of use cases that you are
not personally familiar with or
believe in.
20Copyright (C) 2021 Bryce Adelstein Lelbach
Reality
21Copyright (C) 2021 Bryce Adelstein Lelbach
Acceptable Solutions(for Domain B)
Acceptable Solutions(for Domain C)
Acceptable
Solutions(for Domain A)
Acceptable
Solutions(for Domain D)
What we canactually
standardize
23Copyright (C) 2021 Bryce Adelstein Lelbach
Satisfying 5 million C++ programmers is hard.
Universality
Effort to Standardize
24Copyright (C) 2021 Bryce Adelstein Lelbach
Satisfying 5 million C++ programmers is hard.
Satisfying only one group of C++ programmers is
easier, but is it valuable?
Universality
Effort to Standardize
25Copyright (C) 2021 Bryce Adelstein Lelbach
We should probably try to stay in this space; standardize
features that support many, but not all use cases.
Universality
Effort to Standardize
Should Everything in std:: Support Allocators?
27Copyright (C) 2021 Bryce Adelstein Lelbach
std::vector
Should Everything in std:: Support Allocators?
28Copyright (C) 2021 Bryce Adelstein Lelbach
propagate_on_container_copy_assignmentpropagate_on_container_move_assignment
propagate_on_container_swap
std::vector
Should Everything in std:: Support Allocators?
29Copyright (C) 2021 Bryce Adelstein Lelbach
propagate_on_container_copy_assignmentpropagate_on_container_move_assignment
propagate_on_container_swap
std::vector
std::tuplestd::pair
std::optional
Should Everything in std:: Support Allocators?
30Copyright (C) 2021 Bryce Adelstein Lelbach
propagate_on_container_copy_assignmentpropagate_on_container_move_assignment
propagate_on_container_swap
std::functionstd::generator
std::tuplestd::pair
std::optional
std::vector
Should Everything in std:: Have A Type Erased Form?
template <typename R>requires std::ranges::random_access_range<R>
voidmy_algorithm(R&& r){// ...
}
31Copyright (C) 2021 Bryce Adelstein Lelbach
Should Everything in std:: Have A Type Erased Form?
void my_algorithm(std::any_random_access_range<int> r){// ...
}
32Copyright (C) 2021 Bryce Adelstein Lelbach
Universality Is A Double Edged Sword
33Copyright (C) 2021 Bryce Adelstein Lelbach
Acceptable Solutions(for Domain B)
Acceptable Solutions(for Domain C)
Acceptable
Solutions(for Domain A)
Acceptable
Solutions(for Domain D)
Universality Is A Double Edged Sword
34Copyright (C) 2021 Bryce Adelstein Lelbach
Any Platform
AnyProblem
AnyParadigm
HPC
Gaming
Robotics
Finance
Apps
Vehicles
Imperative
Functional
Parallel
Object Oriented
Generic
Reactive
GCC’s libstdc++ is not the C++ Standard Library.
MSVC’s STL is not the C++ Standard Library.
LLVM’s libc++ is not the C++ Standard Library.
NVIDIA’s libnv++ is not the C++ Standard Library.
37Copyright (C) 2021 Bryce Adelstein Lelbach
GCC’s libstdc++ is not the C++ Standard Library.
MSVC’s STL is not the C++ Standard Library.
LLVM’s libc++ is not the C++ Standard Library.
NVIDIA’s libnv++ is not the C++ Standard Library.
They are C++ Standard Library implementations.
38Copyright (C) 2021 Bryce Adelstein Lelbach
The C++ Standard Library is a
specification.
That makes it an inefficient
vehicle for delivering features.
40Copyright (C) 2021 Bryce Adelstein Lelbach
41Copyright (C) 2021 Bryce Adelstein Lelbach
EngineeringEffort
Other C++ Libraries
Platform Agnostic
Implementation
42Copyright (C) 2021 Bryce Adelstein Lelbach
EngineeringEffort
Other C++ Libraries
Platform Agnostic
Implementation
Platform Specific Code
43Copyright (C) 2021 Bryce Adelstein Lelbach
EngineeringEffort
Other C++ Libraries
Platform Agnostic
Implementation
Platform Specific Code
The C++ Standard Library
LLVM Implementation
44Copyright (C) 2021 Bryce Adelstein Lelbach
EngineeringEffort
Other C++ Libraries
Platform Agnostic
Implementation
Platform Specific Code
The C++ Standard Library
LLVM Implementation
GCC Implementation
45Copyright (C) 2021 Bryce Adelstein Lelbach
EngineeringEffort
Other C++ Libraries
Platform Agnostic
Implementation
Platform Specific Code
The C++ Standard Library
LLVM Implementation
GCC Implementation
MSVC Implementation
47Copyright (C) 2021 Bryce Adelstein Lelbach
Domain A Domain B Domain A
The Standard specifiesenough to be portable and
consistent across platforms.
48Copyright (C) 2021 Bryce Adelstein Lelbach
Domain A Domain B Domain A
The Standard grants enoughfreedom for each platform to choose the right design.
The Standard specifiesenough to be portable and
consistent across platforms.
Implementation Freedom
49Copyright (C) 2021 Bryce Adelstein Lelbach
Domain A Domain B Domain A
The Standard grants enoughfreedom for each platform to choose the right design.
The Standard specifiesenough to be portable and
consistent across platforms.
Implementation-defined and undefined
behavior are often a feature, not a bug.
50Copyright (C) 2021 Bryce Adelstein Lelbach
std::mutex
Implementation Supported On Pros Cons
OS kernel mutexes Older and newer
operating systems.
Fair.
Good perf under contention.
Higher latency.
Futexes Newer operating
systems.
Fair.
Lower latency.
Spinlocks Bare metal. Much lower latency.
Never yields.
Doesn’t need an OS.
Unfair.
Less energy efficient.
No synchronization Single core
platforms.
No overhead.
Doesn’t need an OS.
51Copyright (C) 2021 Bryce Adelstein Lelbach
std::vector::operator[]
std::string::operator[]
52Copyright (C) 2021 Bryce Adelstein Lelbach
Require Out of Bounds Checking
Forbid Out of Bounds CheckingOR
std::vector::operator[]
std::string::operator[]
53Copyright (C) 2021 Bryce Adelstein Lelbach
Require Out of Bounds Checking
Forbid Out of Bounds CheckingOR
std::vector::operator[]
std::string::operator[]
54Copyright (C) 2021 Bryce Adelstein Lelbach
Permit Out of Bounds Checking
Implementation Freedom
55Copyright (C) 2021 Bryce Adelstein Lelbach
The C++ Standard’s more what you’dcall “guidelines” than actual rules
58Copyright (C) 2021 Bryce Adelstein Lelbach
Time to Deployment
AvailabilityOther C++ Libraries
The C++ Standard
Library
59Copyright (C) 2021 Bryce Adelstein Lelbach
Time to Deployment
AvailabilityOther C++ Libraries
The C++ Standard
Library
std:: Implementors Aren’t Domain Experts
60Copyright (C) 2021 Bryce Adelstein Lelbach
People with the skills to build
and maintain C++ Standard
Library implementations
People with the specialized
expertise to implement things
for your domain
std:: Implementors Aren’t Domain Experts
61Copyright (C) 2021 Bryce Adelstein Lelbach
I have no idea what I’m doing
std::regex Performance
62Copyright (C) 2021 Bryce Adelstein Lelbach
Source: github.com/mariomka/regex-benchmark; Hana Dusíková
63Copyright (C) 2021 Bryce Adelstein Lelbach
Implementersare experts at:
➢ Their specific platform.
➢ Balancing tradeoffs.
➢ Handling corner cases.
Implementersare less good at:
➢ Domain specific work:➢ Math special functions
➢ std::regex➢ <charconv>➢ …
Hyrum’s Law:
With a sufficient number of users,
it doesn’t matter what you promise in the contract:
all observable behaviors of your system
will be depended on by somebody.
65Copyright (C) 2021 Bryce Adelstein Lelbach
API: Syntax & semantics.
Source code. In the C++ Standard.
ABI: Binary representation & conventions.
Compiled code. Platform specific.
67Copyright (C) 2021 Bryce Adelstein Lelbach
68Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
69Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ …
70Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ …
71Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ …
72Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ …
73Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ …
74Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
75Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
C++ Standard Library ABI:Binary representation & conventions
for C++ Standard Library facilities.
76Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
C++ Standard Library ABI:Binary representation & conventions
for C++ Standard Library facilities.
➢ Linkage of std:: functions.
➢ …
77Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
C++ Standard Library ABI:Binary representation & conventions
for C++ Standard Library facilities.
➢ Linkage of std:: functions.
➢ std:: name mangling.
➢ …
78Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
C++ Standard Library ABI:Binary representation & conventions
for C++ Standard Library facilities.
➢ Linkage of std:: functions.
➢ std:: name mangling.
➢ Layout and size of std:: types.
➢ …
79Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
C++ Standard Library ABI:Binary representation & conventions
for C++ Standard Library facilities.
➢ Linkage of std:: functions.
➢ std:: name mangling.
➢ Layout and size of std:: types.
➢ std:: Virtual tables.
➢ …
80Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
C++ Standard Library ABI:Binary representation & conventions
for C++ Standard Library facilities.
➢ Linkage of std:: functions.
➢ std:: name mangling.
➢ Layout and size of std:: types.
➢ std:: Virtual tables.
➢ std:: constexpr values and functions.
➢ …
81Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Language ABI:Binary representation & conventions
for language facilities.
➢ Function calling conventions.
➢ Name mangling.
➢ Layout and size of types.
➢ Layout of virtual tables.
➢ Exception handling.
➢ Floating point mathematics.
➢ …
C++ Standard Library ABI:Binary representation & conventions
for C++ Standard Library facilities.
➢ Linkage of std:: functions.
➢ std:: name mangling.
➢ Layout and size of std:: types.
➢ std:: Virtual tables.
➢ std:: constexpr values and functions.
➢ <type_traits> and std:: concepts.
➢ …
API Stability: Existing syntax and
semantics should rarely change.
82Copyright (C) 2021 Bryce Adelstein Lelbach
API Stability: Existing syntax and
semantics should rarely change.
ABI Stability: Binary representations of
existing facilities should rarely change.
83Copyright (C) 2021 Bryce Adelstein Lelbach
85Copyright (C) 2021 Bryce Adelstein Lelbach
B
Compiled as C++23
Written as C++11
A
Compiled as C++23
Written as C++11
Backward Compatibility
86Copyright (C) 2021 Bryce Adelstein Lelbach
B
Compiled as C++23
Written as C++11
A
Compiled as C++23
Written as C++11
Backward Compatibility
A
Compiled as C++23
Written as C++23
B
Compiled as C++11
Written as C++11
87Copyright (C) 2021 Bryce Adelstein Lelbach
B
Compiled as C++23
Written as C++11
A
Compiled as C++23
Written as C++11
Backward Compatibility
C
Compiled as C++23
Written as C++23
D
Compiled as C++11
Written as C++11
88Copyright (C) 2021 Bryce Adelstein Lelbach
B
Compiled as C++23
Written as C++11
A
Compiled as C++23
Written as C++11
Backward Compatibility Forward Compatibility
C
Compiled as C++23
Written as C++23
D
Compiled as C++11
Written as C++11
Backward Compatibility:Newer Builds, Older Code
Forward Compatibility:Older Builds, Newer Code
89Copyright (C) 2021 Bryce Adelstein Lelbach
90Copyright (C) 2021 Bryce Adelstein Lelbach
B
Compiled as C++23
Written as C++11
A
Compiled as C++23
Written as C++11
Backward Compatibility Forward Compatibility
C
Compiled as C++23
Written as C++23
D
Compiled as C++11
Written as C++11
Externally Provided
Dependencies Support All Versions
91Copyright (C) 2021 Bryce Adelstein Lelbach
X
Compiled as C++23
Written as C++11
Y
Compiled as C++11
Written as C++11
std:: (v2)
Compiled as C++23
Written as C++23
std:: (v1)
Compiled as C++11
Written as C++11
Externally Provided
Dependencies Support All Versions
92Copyright (C) 2021 Bryce Adelstein Lelbach
X
Compiled as C++23
Written as C++11
Y
Compiled as C++11
Written as C++11
std:: (v2)
Compiled as C++23
Written as C++23
std:: (v1)
Compiled as C++11
Written as C++11
Externally Provided
Dependencies Support All Versions
93Copyright (C) 2021 Bryce Adelstein Lelbach
X
Compiled as C++23
Written as C++11
Y
Compiled as C++11
Written as C++11
std:: (v2)
Compiled as C++23
Written as C++23
std:: (v1)
Compiled as C++11
Written as C++11
No std::objects
Externally Provided
Write Your ABI Stable Interfaces In C
94Copyright (C) 2021 Bryce Adelstein Lelbach
X
Compiled as C++23
Written as C++11
Y
Compiled as C++11
Written as C++11
Z (v2)
Compiled as C++23
Written as C++23
Z (v1)
Compiled as C++11
Written as C++11
CInterface
Externally Provided
You Build All Dependencies
95Copyright (C) 2021 Bryce Adelstein Lelbach
Z
Compiled as C++23
Written as C++23
X
Compiled as C++23
Written as C++11
Y
Compiled as C++23
Written as C++11
The Don’t Upgrade Solution:
If you can’t get newer dependency builds,
don’t upgrade to a new C++ dialect.
96Copyright (C) 2021 Bryce Adelstein Lelbach
98Copyright (C) 2021 Bryce Adelstein Lelbach
Builds from different C++ dialects
can’t be mixed.
A project takes longer to move to
new C++ dialects.
99Copyright (C) 2021 Bryce Adelstein Lelbach
Builds from different C++ dialects
can’t be mixed.
Things that depend on it take
longer to move to new C++ dialects
A project takes longer to move to
new C++ dialects.
100Copyright (C) 2021 Bryce Adelstein Lelbach
Builds from different C++ dialects
can’t be mixed.
Things that depend on it take
longer to move to new C++ dialects
A project takes longer to move to
new C++ dialects.
103Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Build Time?➢ Compile Time?
How does a breaking change manifest?
104Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Build Time?➢ Compile Time?➢ Link Time?
How does a breaking change manifest?
105Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Build Time?➢ Compile Time?➢ Link Time?
➢ Run Time?
How does a breaking change manifest?
106Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Build Time?➢ Compile Time?➢ Link Time?
➢ Run Time?➢ Graceful?
How does a breaking change manifest?
107Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Build Time?➢ Compile Time?➢ Link Time?
➢ Run Time?➢ Graceful?➢ Catastrophic?
How does a breaking change manifest?
108Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Build Time?➢ Compile Time?➢ Link Time?
➢ Run Time?➢ Graceful?➢ Catastrophic?
➢ Undefined Behavior?
How does a breaking change manifest?
std:: Parameters Exposes You To ABI Breaks
109Copyright (C) 2021 Bryce Adelstein Lelbach
void f(std::string& s) { /* ... */ }
A Compiled as C++11
B Compiled as C++23
void g() {f(std::string("BAL"));
}
std:: Parameters Exposes You To ABI Breaks
110Copyright (C) 2021 Bryce Adelstein Lelbach
void f(std::string& s) { /* ... */ }
A Compiled as C++11
B Compiled as C++23
void g() {f(std::string("BAL"));
}
std:: Return Types Exposes You To ABI Breaks
111Copyright (C) 2021 Bryce Adelstein Lelbach
std::string f() { /* ... */ }
A Compiled as C++11
B Compiled as C++23
std::string g() {std::string s = f();return s + "bryce";
}
std:: Data Members Exposes You To ABI Breaks
112Copyright (C) 2021 Bryce Adelstein Lelbach
struct X {std::string s;
};X make_x();
A Compiled as C++11
void g() {X x = make_x();x.s = "hello world\n";
}
B Compiled with C++23
Inlining Of std:: Exposes You To ABI Breaks
void f() {std::string s;s.reserve(42);s += "adelstein";
}
113Copyright (C) 2021 Bryce Adelstein Lelbach
Inlining Of std:: Exposes You To ABI Breaks
void f() {std::string s;s.reserve(42); // What if this is inlined,s += "adelstein"; // but this isn’t?
}
114Copyright (C) 2021 Bryce Adelstein Lelbach
constexpr std:: Values Expose You To ABI Breaks
struct ticket_mutex {alignas(std::hardware_destructive_interference_size)
std::atomic<int> in; alignas(std::hardware_destructive_interference_size)
std::atomic<int> out;};
115Copyright (C) 2021 Bryce Adelstein Lelbach
std:: Default Params Expose You To ABI Breaks
namespace std {
template <class T, std::size_t E = std::dynamic_extent>class span;
}
116Copyright (C) 2021 Bryce Adelstein Lelbach
std:: Default Params Expose You To ABI Breaks
namespace std {
template <class T, std::size_t E = std::dynamic_extent>class span;
}
void f(std::span<int>);
117Copyright (C) 2021 Bryce Adelstein Lelbach
std:: Concepts Expose You To ABI Breaks
template <typename InputIt, typename OutputIt>using intermediate_type = std::conditional_t<std::input_iterator<OutputIt>,typename std::iterator_traits<OutputIt>::value_type,typename std::iterator_traits<InputIt>::value_type
>;
118Copyright (C) 2021 Bryce Adelstein Lelbach
Polymorphism In std:: Exposes You To ABI Breaks
119Copyright (C) 2021 Bryce Adelstein Lelbach
Removing virtual functionscauses layout changes.
Polymorphism In std:: Exposes You To ABI Breaks
120Copyright (C) 2021 Bryce Adelstein Lelbach
Adding virtual functionscauses layout changes.
Removing virtual functionscauses layout changes.
In most cases, we can add
functionality to facilities while
preserving ABI.
For polymorphism, type erasure,
and named concepts, adding
functionality usually breaks ABI.
121Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Standard Library
polymorphism,
type erasure, and
named concepts
are fixed forever.
122Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Standard Library
polymorphism,
type erasure, and
named concepts
are fixed forever.
123Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Standard Library
polymorphism,
type erasure, and
named concepts
are fixed forever.
124Copyright (C) 2021 Bryce Adelstein Lelbach
C++11 std::list::size Complexity
C++03: std::list::size can have
linear complexity. No size data member
needed.
template <class T,class A = std::allocator<T>>
class std::list {__list_node<T> root;
};
sizeof(std::list<int>) == 16
125Copyright (C) 2021 Bryce Adelstein Lelbach
C++11 std::list::size Complexity
C++03: std::list::size can have
linear complexity. No size data member
needed.
template <class T,class A = std::allocator<T>>
class std::list {__list_node<T> root;
};
sizeof(std::list<int>) == 16
126Copyright (C) 2021 Bryce Adelstein Lelbach
C++11: std::list::size must have
linear complexity. A size data member
is required.
template <class T,class A = std::allocator<T>>
class std::list {__list_node<T> root;std::size_t size;
};
sizeof(std::list<int>) == 24
C++11 std::string COW Prohibition
127Copyright (C) 2021 Bryce Adelstein Lelbach
__string_rep*
std::string b
__string_rep*
std::string a
__string_rep*
std::string c
l e l b a c h
In C++03 copy-on-write was allowed.
char*
size & capacity
__string_rep 0
C++11 std::string COW Prohibition
128Copyright (C) 2021 Bryce Adelstein Lelbach
__string_rep*
std::string b
__string_rep*
std::string a
__string_rep*
std::string c
l e l b a c h L E L B A C H
In C++03 copy-on-write was allowed.
char*
size & capacity
__string_rep 1
char*
size & capacity
__string_rep 0
C++11 std::string COW Prohibition
129Copyright (C) 2021 Bryce Adelstein Lelbach
__string_rep*
std::string b
__string_rep*
std::string a
__string_rep*
std::string c
l e l b a c h L E L B A C H
In C++03 copy-on-write was allowed.
char*
size & capacity
__string_rep 1
char*
size & capacity
__string_rep 0
C++11 std::string COW Prohibition
130Copyright (C) 2021 Bryce Adelstein Lelbach
__string_rep*
std::string b
__string_rep*
std::string a
__string_rep*
std::string c
l e l b a c h L E L B A C H
In C++03 copy-on-write was allowed.
size & capacity
std::string a
char*
l e l b a c h L E L B A C H
But in C++11, we prohibited it.
char*
size & capacity
__string_rep 1
char*
size & capacity
__string_rep 0
size & capacity
std::string b
char*
l e l b a c h
std::string b
size & capacity
char*
C++11 std::string COW Prohibition
131Copyright (C) 2021 Bryce Adelstein Lelbach
__string_rep*
std::string b
__string_rep*
std::string a
__string_rep*
std::string c
l e l b a c h L E L B A C H
In C++03 copy-on-write was allowed.
size
std::string a
l e l b a c h
But in C++11, we prohibited it.
char*
size & capacity
__string_rep 1
char*
size & capacity
__string_rep 0
L E L B A C H
size
std::string b
size
std::string b
l e l b a c h
Where the C++11 std::listand std::string breaks the
right decision?
132Copyright (C) 2021 Bryce Adelstein Lelbach
C++17 Variadic std::lock_guard
template <class MutexType>struct std::lock_guard;
{std::lock_guard<std::mutex> l0(mtx0);std::lock_guard<std::mutex> l1(mtx1);// ...
}
133Copyright (C) 2021 Bryce Adelstein Lelbach
C++17 Variadic std::lock_guard
template <class... MutexTypes>struct std::lock_guard;
{std::lock_guard l(mtx0, mtx1);// ...
}
134Copyright (C) 2021 Bryce Adelstein Lelbach
C++17 Variadic std::lock_guard
135Copyright (C) 2021 Bryce Adelstein Lelbach
template <class MutexType>struct std::lock_guard {};
void f(std::lock_guard<std::mutex>);
_Z1fSt10lock_guardISt5mutexE
template <class... MutexTypes>struct std::lock_guard {};
void f(std::lock_guard<std::mutex>);
_Z1fSt10lock_guardIJSt5mutexEE
C++17 Variadic std::lock_guard
136Copyright (C) 2021 Bryce Adelstein Lelbach
template <class MutexType>struct std::lock_guard {};
void f(std::lock_guard<std::mutex>);
_Z1fSt10lock_guardISt5mutexE
template <class... MutexTypes>struct std::scoped_lock {};
void f(std::scoped_lock<std::mutex>);
_Z1fSt11scoped_lockIJSt5mutexEE
C++17 Non-Allocating std::system_error::message
137Copyright (C) 2021 Bryce Adelstein Lelbach
virtual~error_category();
virtual char const*name() const noexcept = 0;
virtual error_conditiondefault_error_condition(int) const noexcept;
virtual boolequivalent(int, error_condition const&) const noexcept;
virtual char const*message(int, char*, size) const = 0;
virtual boolequivalent(error_code const&, int) const noexcept;
virtual char const*message(int, char*, size_t) const noexcept;
Proposed addition was non-pure; existing derived classes would continue to compile.
std::mutex Performance with MSVC
138Copyright (C) 2021 Bryce Adelstein Lelbach
0
0.5
1
1.5
2
2.5
2 Threads 4 Threads 8 Threads
Sp
ee
du
p
std::mutex std::shared_mutexSource: programming.vip/docs/performance-comparison-between-std-shared_mutex-and-std-mutex-banchmark.html
std::mutex Performance with MSVC
sizeof(std::mutex) == 80
sizeof(std::shared_mutex) == 8
139Copyright (C) 2021 Bryce Adelstein Lelbach
141Copyright (C) 2021 Bryce Adelstein Lelbach
The C++ Standard Library is:
➢ Good at stability.
➢ Bad at fixing mistakes.
Stability vs Velocity is a myth.
We can’t make a binary choice here.
144Copyright (C) 2021 Bryce Adelstein Lelbach
Today, all major implementations
guarantee some degree of
long term stability.
It is unrealistic to think we will
stop caring about stability.
145Copyright (C) 2021 Bryce Adelstein Lelbach
But stability inhibits velocity.
We can’t fix this via policy.
147Copyright (C) 2021 Bryce Adelstein Lelbach
But stability inhibits velocity.
We can’t fix this via policy.
We need technical solutions.
148Copyright (C) 2021 Bryce Adelstein Lelbach
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
149Copyright (C) 2021 Bryce Adelstein Lelbach
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
150Copyright (C) 2021 Bryce Adelstein Lelbach
B Compiled as C++23
void g() {std::string s("BAL");f(s);
}
void f(std::string& s) {/* ... */
}
A Compiled as C++11
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
151Copyright (C) 2021 Bryce Adelstein Lelbach
B Compiled as C++23
void g() {std::__cxx23::string s("BAL");f(s);
}
void f(std::__cxx11::string& s) {/* ... */
}
A Compiled as C++11
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
152Copyright (C) 2021 Bryce Adelstein Lelbach
B Compiled as C++23
void g() {std::string s(/* ... */);f(s);
}_Z1fRNSt7__cxx2312basic_stringIcSt11char_traitsIcESaIcEEEExpected Mangling:
void f(std::string& s) {/* ... */
}
A Compiled as C++11
_Z1fRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Mangling:
Inline Namespaces
namespace std {inline namespace __cxx11 {
using string = basic_string<char>;
}
inline namespace __cxx23 {
using string = basic_string<char>;
}}
153Copyright (C) 2021 Bryce Adelstein Lelbach
B Compiled as C++23
void g() {std::__cxx11::string s(/* ... */);f(s);
}
void f(std::string& s) {/* ... */
}
A Compiled as C++11
Inline Namespaces
namespace std {inline namespace __cxx11 {
using string = basic_string<char>;
}
inline namespace __cxx23 {
using string = basic_string<char>;
}}
154Copyright (C) 2021 Bryce Adelstein Lelbach
B Compiled as C++23
void g() {std::__cxx11::string s(/* ... */);f(s);
}
void f(std::string& s) {/* ... */
}
A Compiled as C++11
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
155Copyright (C) 2021 Bryce Adelstein Lelbach
std::string f() {/* ... */
}
A Compiled as C++11
B Compiled as C++23
std::string g() {std::string s = f();return s + "bryce";
}
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
156Copyright (C) 2021 Bryce Adelstein Lelbach
B Compiled as C++23
std::__cxx23::string g() {std::__cxx23::string s = f();return s + "bryce";
} _Z1fvExpected Mangling:
std::__cxx11::string f() {/* ... */
}
A Compiled as C++11
_Z1fvMangling:
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
157Copyright (C) 2021 Bryce Adelstein Lelbach
std::__cxx11::string f() {/* ... */
}
A Compiled as C++11
B Compiled as C++23
std::__cxx23::string g() {std::__cxx23::string s = f();return s + "bryce";
} SILENT ODR VIOLATION
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
158Copyright (C) 2021 Bryce Adelstein Lelbach
struct X {std::string s;
};X make_x();
A Compiled as C++11
B Compiled as C++23
struct X {std::string s;
};void g() { X x = make_x(); }
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
159Copyright (C) 2021 Bryce Adelstein Lelbach
struct X {std::__cxx11::string s;
};X make_x();
A Compiled as C++11
B Compiled as C++23
struct X {std::__cxx23::string s;
};void g() { X x = make_x(); }
SILENT ODR VIOLATION
Inline Namespaces
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
160Copyright (C) 2021 Bryce Adelstein Lelbach
ABI Problem Diagnoses? Solves?
Parameters
Return Types
Non-Local Variables
Data Members
Inlining
Constant Evaluation
Polymorphism
abi_tag
namespace std {inline namespace __cxxNN __attribute__((abi_tag)) {
// ...
}}
Viral;
if something with an ABI tag is in a function’s
signature, then the function gets an ABI tag.
161Copyright (C) 2021 Bryce Adelstein Lelbach
abi_tag
namespace std {inline namespace __cxxNN {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
162Copyright (C) 2021 Bryce Adelstein Lelbach
B Compiled as C++23
std::__cxx23::string g() {std::__cxx23::string s = f();return s + "bryce";
} _Z1fvExpected Mangling:
std::__cxx11::string f() {/* ... */
}
A Compiled as C++11
_Z1fvMangling:
namespace std {inline namespace __cxxNN
__attribute__((abi_tag)) {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
163Copyright (C) 2021 Bryce Adelstein Lelbach
std::__cxx11::string f() {/* ... */
}
A Compiled as C++11
_Z1fB7__cxx11vMangling:
B Compiled as C++23
std::__cxx23::string g() {std::__cxx23::string s = f();return s + "bryce";
} _Z1fB7__cxx23vExpected Mangling:
abi_tag
namespace std {inline namespace __cxxNN
__attribute__((abi_tag)) {
template <class C,class T = std::char_traits<C>,class A = std::allocator<C>>
class basic_string;
using string = basic_string<char>;
}}
164Copyright (C) 2021 Bryce Adelstein Lelbach
ABI Problem Diagnoses? Solves?
Parameters
Return Types
Non-Local Variables
Data Members
Inlining
Constant Evaluation
Polymorphism
abi_tag
std2::Introduce new version of existing std::features which are not compatible, but
might be interoperable.
165Copyright (C) 2021 Bryce Adelstein Lelbach
void f(std::__cxx20::string& s);void f(std::__cxx23::string& s);
void f(std::string& s);void f(std2::string& s);
Are these ambiguous, or necessary?
166Copyright (C) 2021 Bryce Adelstein Lelbach
std2:: Approach
Any solution equivalent to
“duplicate and maintain multiple
generations of the same facilities”.
167Copyright (C) 2021 Bryce Adelstein Lelbach
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
168Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
169Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
170Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
171Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
172Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
173Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
174Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
struct point {interface(std::cxx23) {int x, y, z;interface(std::cxx26) int w;
int get_x() const { return x; }int get_y() const { return y; }int get_z() const { return z; }
int get_w() const interface(std::cxx26) { return w; }}
};
sizeof(interface(std::cxx23) point) == 12sizeof(interface(std::cxx26) point) == 16
175Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
void f(interface(std::cxx23) std::string& s);
176Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
void f(interface(std::cxx23) std::string& s);
void f(interface(std::cxx23+) std::string& s);
177Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
void f(interface(std::cxx23) std::string& s);
void f(interface(std::cxx23+) std::string& s);
178Copyright (C) 2021 Bryce Adelstein Lelbach
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
Interfaces
179Copyright (C) 2021 Bryce Adelstein Lelbach
ABI Problem Diagnoses? Solves?
Parameters
Return Types
Non-Local Variables
Data Members
Inlining
Constant Evaluation
Polymorphism
Source: P2123: Extending The Type System To Provide API And ABI Flexibility; Hal Finkel & Tom Scogland
The Stability Thesis:
Until we learn to change
things after we ship them,
the C++ Standard Library should
only contain things that are
unlikely to need many changes.
180Copyright (C) 2021 Bryce Adelstein Lelbach
Today, the C++ Standard Library is:
➢ Good at stability.
➢ Bad at fixing mistakes.
181Copyright (C) 2021 Bryce Adelstein Lelbach
The C++ Standard Library
shouldn’t innovate.
The C++ community
should innovate.
182Copyright (C) 2021 Bryce Adelstein Lelbach
The C++ Standard Library should
standardize existing practice.
183Copyright (C) 2021 Bryce Adelstein Lelbach
Anything that goes into the
C++ Standard Library must
stand the test of time.
Will we be happy with it in
10 to 20 years?
184Copyright (C) 2021 Bryce Adelstein Lelbach
Avoid premature standardization
in evolving fields.
If there’s substantial active research,
or the best practices change every
few years, it’s not ready yet.
185Copyright (C) 2021 Bryce Adelstein Lelbach
std:: Unordered Containers Performance
186Copyright (C) 2021 Bryce Adelstein Lelbach
Source: Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step; Matt Kulukundis; CppCon 2017
We need to see field experience before
we can standardize.
187Copyright (C) 2021 Bryce Adelstein Lelbach
Implementation Experience:Experience implementing
a proposed design.
188Copyright (C) 2021 Bryce Adelstein Lelbach
189Copyright (C) 2021 Bryce Adelstein Lelbach
Good Implementation Experience
Better Implementation Experience
Prototype. Production.
Preceding or similar to the
standard.
Written from or conforming
to the standard.
For one platform. For multiple platforms.
In any publicly available
codebase.
In a C++ Standard Library
codebase.
Usage Experience:Experience using implementations
of the proposed design.
190Copyright (C) 2021 Bryce Adelstein Lelbach
Deployment Experience:Experience evolving and maintaining
the proposed design over time.
191Copyright (C) 2021 Bryce Adelstein Lelbach
Field Experience:
➢ Implementation Experience.
➢ Usage Experience.
➢ Deployment Experience.
192Copyright (C) 2021 Bryce Adelstein Lelbach
193Copyright (C) 2021 Bryce Adelstein Lelbach
If we can’t change a feature after it ships, then we should…
SmallerScope
LargerScope
Ship only what is needed;we may be unable to
fix any mistakes.
194Copyright (C) 2021 Bryce Adelstein Lelbach
If we can’t change a feature after it ships, then we should…
SmallerScope
LargerScope
Ship only what is needed;we may be unable to
fix any mistakes.
Ship as much as possible;we may be unable to
add more later.
195Copyright (C) 2021 Bryce Adelstein Lelbach
If we can’t change a feature after it ships, then we should…
SmallerScope
LargerScope
Ship only what is needed;we may be unable to
fix any mistakes.
Ship as much as possible;we may be unable to
add more later.
Incrementalism is key to
C++ Standard Library Evolution.
We’re bad at changing things,
but we’re good at extending things.
196Copyright (C) 2021 Bryce Adelstein Lelbach
197Copyright (C) 2021 Bryce Adelstein Lelbach
If we don’t include this in the initial release of the
feature, is it a breaking change to add it later?
198Copyright (C) 2021 Bryce Adelstein Lelbach
It must be included in
the initial release.
If we don’t include this in the initial release of the
feature, is it a breaking change to add it later?
YES
199Copyright (C) 2021 Bryce Adelstein Lelbach
It must be included in
the initial release.
Does the feature have
any value without it?
If we don’t include this in the initial release of the
feature, is it a breaking change to add it later?
NOYES
200Copyright (C) 2021 Bryce Adelstein Lelbach
It must be included in
the initial release.
Does the feature have
any value without it?
NO
If we don’t include this in the initial release of the
feature, is it a breaking change to add it later?
NOYES
201Copyright (C) 2021 Bryce Adelstein Lelbach
It must be included in
the initial release.
It can be excluded from
the initial release.
Does the feature have
any value without it?
YESNO
If we don’t include this in the initial release of the
feature, is it a breaking change to add it later?
NOYES
The Stability Thesis:
Until we learn to change
things after we ship them,
the C++ Standard Library should
only contain things that are
unlikely to need many changes.
202Copyright (C) 2021 Bryce Adelstein Lelbach
The Necessity Thesis:
The C++ Standard Library
should only contain facilities
that can’t live elsewhere.
203Copyright (C) 2021 Bryce Adelstein Lelbach
Language Support:
Facilities that require
language support for correct
or optimal implementation.
204Copyright (C) 2021 Bryce Adelstein Lelbach
207Copyright (C) 2021 Bryce Adelstein Lelbach
➢ <type_traits>
➢ std::stacktrace
➢ std::tuple_element
Language Support:
208Copyright (C) 2021 Bryce Adelstein Lelbach
➢ <type_traits>
➢ std::stacktrace
➢ std::tuple_element
➢ std::memcpy
Language Support:
Portability:
Facilities that provide portable
abstractions of platform-specific
behavior and interfaces.
209Copyright (C) 2021 Bryce Adelstein Lelbach
213Copyright (C) 2021 Bryce Adelstein Lelbach
➢ std::chrono
➢ std::atomic
➢ std::sort
➢ std::numeric_limits
Portability:
Vocabulary:
Facilities that need a common
definition for interoperability
across the C++ ecosystem.
214Copyright (C) 2021 Bryce Adelstein Lelbach
Interface Vocabulary:
Concepts, types, and operations that
commonly appear in C++ interfaces.
Common definitions means different
codebases can interoperate.
215Copyright (C) 2021 Bryce Adelstein Lelbach
Interface Vocabulary:
void my_f(std::ranges::input_range&& r);void your_f(std::ranges::input_range&& r);
216Copyright (C) 2021 Bryce Adelstein Lelbach
Interface Vocabulary:
void my_f(std::ranges::input_range&& r);void your_f(std::ranges::input_range&& r);
void my_g(std::string_view s);void your_g(std::string_view s);
217Copyright (C) 2021 Bryce Adelstein Lelbach
Interface Vocabulary:
void my_f(std::ranges::input_range&& r);void your_f(std::ranges::input_range&& r);
void my_g(std::string_view s);void your_g(std::string_view s);
218Copyright (C) 2021 Bryce Adelstein Lelbach
220Copyright (C) 2021 Bryce Adelstein Lelbach
Interface Vocabulary:➢ Concepts
➢ Containers and Views
221Copyright (C) 2021 Bryce Adelstein Lelbach
Interface Vocabulary:➢ Concepts
➢ Containers and Views
➢ <algorithm>
222Copyright (C) 2021 Bryce Adelstein Lelbach
Interface Vocabulary:➢ Concepts
➢ Containers and Views
➢ <algorithm>
➢ std::format
223Copyright (C) 2021 Bryce Adelstein Lelbach
Tooling Vocabulary:
Facilities that tools want to recognize.
224Copyright (C) 2021 Bryce Adelstein Lelbach
➢ MSVC iterator debugging.
➢ GDB container pretty printing.
Tooling Vocabulary:
Facilities that tools want to recognize.
225Copyright (C) 2021 Bryce Adelstein Lelbach
➢ MSVC iterator debugging.
➢ GDB container pretty printing.
➢ Clang thread safety analysis.
Tooling Vocabulary:
Facilities that tools want to recognize.
226Copyright (C) 2021 Bryce Adelstein Lelbach
The Necessity Thesis:
The C++ Standard Library should only
contain facilities that can’t live elsewhere.
➢ Language Support
➢ Portability
➢ Vocabulary
229Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Asynchrony & Parallelism
C++ Standard Library priorities for 2020s:
230Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Asynchrony & Parallelism
➢ Input & Output
C++ Standard Library priorities for 2020s:
231Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Asynchrony & Parallelism
➢ Input & Output
➢ Text Processing
C++ Standard Library priorities for 2020s:
232Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Asynchrony & Parallelism
➢ Input & Output
➢ Text Processing
➢ Metaprogramming & Reflection
C++ Standard Library priorities for 2020s:
The Usefulness Thesis:
The C++ Standard Library should
expand in scope to contain
anything that is useful to C++
programmers.
233Copyright (C) 2021 Bryce Adelstein Lelbach
I hate to be the person that
says we can’t have nice things,
but nice is not a sufficient
motivation for standardization.
234Copyright (C) 2021 Bryce Adelstein Lelbach
The Burden Of Being In std::
➢ Must be ABI stable.
➢ Must support every C++ compiler and platform.
➢ Must support every corner case.
➢ Must support every compilation mode.
➢ …
235Copyright (C) 2021 Bryce Adelstein Lelbach
237Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
238Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
NOThere’s no existing practice;
how could we standardize it?
239Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it?
240Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it?
My company or project only lets me use things in the C++ Standard
Library.
241Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it?
My company or project only lets me use things in the C++ Standard
Library.
Standardization
is not a
substitute for
culture change.
242Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it? There’s a specific reason it would be better in the
C++ Standard Library.
My company or project only lets me use things in the C++ Standard
Library.
Standardization
is not a
substitute for
culture change.
243Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it? There’s a specific reason it would be better in the
C++ Standard Library.
Can you live with making no breaking
changes to it for the next 20 years?
My company or project only lets me use things in the C++ Standard
Library.
Standardization
is not a
substitute for
culture change.
244Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it? There’s a specific reason it would be better in the
C++ Standard Library.
Is it worth 5x the effort and time that
it would take just to put it on GitHub?
Can you live with making no breaking
changes to it for the next 20 years?
My company or project only lets me use things in the C++ Standard
Library.
Standardization
is not a
substitute for
culture change.
YES
245Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it? There’s a specific reason it would be better in the
C++ Standard Library.
Is it worth 5x the effort and time that
it would take just to put it on GitHub?
Okay let’s talk.
Can you live with making no breaking
changes to it for the next 20 years?
My company or project only lets me use things in the C++ Standard
Library.
Standardization
is not a
substitute for
culture change.
YES
YES
246Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it? There’s a specific reason it would be better in the
C++ Standard Library.
Is it worth 5x the effort and time that
it would take just to put it on GitHub?
Okay let’s talk.
Can you live with making no breaking
changes to it for the next 20 years?
My company or project only lets me use things in the C++ Standard
Library.
Standardization
is not a
substitute for
culture change.
YES
YES
Managing
dependencies
is hard.
Have you tried a C++
package manager?
247Copyright (C) 2021 Bryce Adelstein Lelbach
Is there a popular C++ library that has the facility you want to add to the C++ Standard Library?
YESNO
Why isn’t that
good enough?
There’s no existing practice;
how could we standardize it? There’s a specific reason it would be better in the
C++ Standard Library.
Is it worth 5x the effort and time that
it would take just to put it on GitHub?
Okay let’s talk.
Can you live with making no breaking
changes to it for the next 20 years?
My company or project only lets me use things in the C++ Standard
Library.
Standardization
is not a
substitute for
culture change.
Managing
dependencies
is hard. YESNO
YESNO
The problem isn’t that C++ has no package manager.
The problem is that there are too many.
249Copyright (C) 2021 Bryce Adelstein Lelbach
b | 2
As C++ committee members, package
management may be out of our scope.
251Copyright (C) 2021 Bryce Adelstein Lelbach
As C++ committee members, package
management may be out of our scope.
As leaders of the C++ community, it is
our duty and responsibility to act.
252Copyright (C) 2021 Bryce Adelstein Lelbach
Using external libraries in C++
should be an order of magnitude
easier than it is today.
This should be the primary goal
for C++ in the next decade.
253Copyright (C) 2021 Bryce Adelstein Lelbach
255Copyright (C) 2021 Bryce Adelstein Lelbach
What would we even standardize?
➢ C++ package metadata formats?
➢ ...
256Copyright (C) 2021 Bryce Adelstein Lelbach
What would we even standardize?
➢ C++ package metadata formats?
➢ A C++ package manager?
➢ ...
257Copyright (C) 2021 Bryce Adelstein Lelbach
What would we even standardize?
➢ C++ package metadata formats?
➢ A C++ package manager?
➢ Centralized C++ package repository?
➢ ...
258Copyright (C) 2021 Bryce Adelstein Lelbach
What would we even standardize?
➢ C++ package metadata formats?
➢ A C++ package manager?
➢ Centralized C++ package repository?
➢ A C++ build system?
➢ ...
CMake Is The Standard C++ Build System
259Copyright (C) 2021 Bryce Adelstein Lelbach
0%
20%
40%
60%
80%
100%
2017 2018 2019 2020
Market Share
Source: jetbrains.com/lp/devecosystem-2020/cpp, etc
Standardizing C++ Package Management
260Copyright (C) 2021 Bryce Adelstein Lelbach
conan.io
Package
Description
vcpkg
Package
Description
Spack
Package
Description
Build
System
C++
Source
Code
conan.io
Package
vcpkg
Package
Spack
Package
Standardizing C++ Package Management
261Copyright (C) 2021 Bryce Adelstein Lelbach
CMake Build
System
C++
Source
Code
conan.io
Package
vcpkg
Package
Spack
Package
Standard
Package
Description
Standardizing C++ Package Management
262Copyright (C) 2021 Bryce Adelstein Lelbach
CMake Build
System
C++
Source
Code
conan.io
Package
vcpkg
Package
Spack
Package
Standard
Package
Description
Standardizing C++ Package Management
263Copyright (C) 2021 Bryce Adelstein Lelbach
CMake Build
System
C++
Source
Code
conan.io
Package
vcpkg
Package
Spack
Package
Standard
Package
Description
Package
Name Registry
264Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Standard Library External Libraries
➢ Comes with toolchain
by default.
➢ Works everywhere.
➢ Optionally comes with
toolchain.
➢ Single implementation.
➢ Flexible stability
guarantees.
➢ Single implementation.
➢ Flexible stability
guarantees.
➢ Implementations
duplicates work.
➢ 10-20 year stability
guarantees.
➢ Must support a broad
range of platforms.
➢ Must be acquired
separately; aren’t
available by default.
265Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Standard Library External Libraries
➢ Comes with toolchain
by default.
➢ Works everywhere.
➢ Optionally comes with
toolchain.
➢ Single implementation.
➢ Flexible stability
guarantees.
➢ Single implementation.
➢ Narrower scope.
➢ Flexible stability
guarantees.
➢ Implementations
duplicates work.
➢ 10-20 year stability
guarantees.
➢ Must support a broad
range of platforms.
➢ Must be acquired
separately; aren’t
available by default.
266Copyright (C) 2021 Bryce Adelstein Lelbach
C++ Standard Library C++ Collections External Libraries
➢ Comes with toolchain
by default.
➢ Works everywhere.
➢ Optionally comes with
toolchain.
➢ Single implementation.
➢ Flexible stability
guarantees.
➢ Single implementation.
➢ Narrower scope.
➢ Flexible stability
guarantees.
➢ Implementations
duplicates work.
➢ 10-20 year stability
guarantees.
➢ Must support a broad
range of platforms.
➢ Must be acquired
separately; aren’t
available by default.
The Stability Thesis:
Until we learn to change
things after we ship them,
the C++ Standard Library should
only contain things that are
unlikely to need major changes.
267Copyright (C) 2021 Bryce Adelstein Lelbach
268Copyright (C) 2021 Bryce Adelstein Lelbach
The Necessity Thesis:
The C++ Standard Library should only
contain facilities that can’t live elsewhere.
➢ Language Support
➢ Portability
➢ Vocabulary
We must find a balance
between Stability and Velocity.
We need new tools to
make that happen.
269Copyright (C) 2021 Bryce Adelstein Lelbach
Using external libraries in C++
should be an order of magnitude
easier than it is today.
This should be the primary goal
for C++ in the next decade.
270Copyright (C) 2021 Bryce Adelstein Lelbach
Thanks
271Copyright (C) 2021 Bryce Adelstein Lelbach
➢ Hana Dusíková
➢ Conor Hoekstra
➢ Billy O’Neal
➢ Olivier Giroux
➢ Michał Dominiak
➢ Tom Honermann
➢ Corentin Jabot
➢ Matt Kulukundis
➢ Casey Carter
➢ Matt Calabrese