Loading…
C++Now 2019 has ended
Thursday, May 9 • 09:00 - 10:30
Trivially Relocatable

Log in to save this to your schedule and see who's attending!

Feedback form is now closed.
At C++Now 2018, Arthur presented three candidates for "The Best Type Trait C++ Doesn't Have." One of these candidates was `is_trivially_relocatable<T>`, as seen in popular third-party libraries such as Folly, BSL, and EASTL. In the past twelve months, Arthur has implemented `__is_trivially_relocatable(T)` in a branch of Clang, made it available on Godbolt Compiler Explorer, and written it up in a proposal targeting the C++2b standard — P1144 "Object relocation in terms of move plus destroy."

In this talk, we'll explain again what "relocation" is and why it's important. (It's the operation consisting of a move-construction and a destruction which is the backbone of vector reallocation, type-erased move-construction, and swap.) We'll explain five common library optimizations that are today applied conservatively only to "trivially copyable" types such as `int*`, and show that they can be applied just as well to "trivially relocatable" types such as `unique_ptr<int>`. Time permitting, we may show benchmarks similar to last year's 3x speedup on `vector::resize`.

Most importantly, Arthur will list several things that P1144 object relocation is NOT, and explain each of them briefly, with examples. P1144 object relocation is NOT N4158 "Destructive Move" (Pablo Halpern, 2014): We'll briefly explain N4158's mechanism and its rejection by the Committee, then show how P1144 addresses those problems. P1144 object relocation is NOT data-structure-level "position-independence" or "persistability": Arthur will explain why he believes P1144 doesn't get C++ any closer to foolproof position-independent data structures. P1144 "trivially relocatable" is NOT Itanium's "trivial for purposes of ABI" attribute: Arthur will explain why they're orthogonal.

Finally, we'll discuss open design issues. There are three reasonable syntax proposals, currently named [[trivially_relocatable]], [[maybe_trivially_relocatable]], and [[trivially_relocatable(bool)]]; we'll compare examples of library code using each of these syntaxes. We'll ask what we ought to require of a trivially relocatable type's copy constructor and assignment operators. And we'll relate P1144's object-lifetime issues to P0593 "Implicit creation of objects for low-level object manipulation."

Speakers
avatar for Arthur O'Dwyer

Arthur O'Dwyer

Arthur O'Dwyer is the author of "Colossal Cave: The Board Game," "Mastering the C++17 STL" (the book), and "The STL From Scratch" (the training course). He runs professional C++ training courses, is occasionally active on the C++ Standards Committee, and has a blog mostly about C... Read More →


Thursday May 9, 2019 09:00 - 10:30
Flug Auditorium

Attendees (41)