Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

The Best Type Traits that C++ Doesn't Have

CppNow via YouTube

Overview

Explore the intricacies of C++ type traits in this comprehensive conference talk from C++Now 2018. Dive into three proposed type traits that could enhance C++ functionality: is_trivially_relocatable_v, is_trivially_equality_comparable_v, and tombstone_traits. Examine how these traits can optimize operations like vector resizing, hash-table rehashing, and compare-exchange on atomic. Analyze benchmarks demonstrating performance improvements, particularly for vector operations. Discover how the introduction of "operator spaceship" in C++2a impacts trivial comparability. Learn about the concept of "tombstone traits" and how they can expose spare representations in types like bool and reference_wrapper. Gain insights into implementing these traits in library classes such as optional and cuckoo_hash. Follow along with code examples, benchmarks, and in-depth explanations of the design criteria and potential compiler support for these proposed traits.

Syllabus

Intro
Outline
Rules for std::vector reallocation
Relocating trivially copyable types
Relocating non-trivial types
Algorithm uninitialized_relocate
Optimizing uninitialized_relocate
By the way: convenience helpers
Two new customization points
Implementing allocator_traits::htcad
TLDR / dependency graph
Benchmark results
Motivating "comparison"
Compiler support required?
Compiler support attained(?)
Another problem: naming
What is the meaning of "trivial"?
Motivating "tombstones"
Design criteria
One new traits class
Specialization for string
Specialization for bool
optional uses tombstone_traits
Recursing on tombstone_traits
Benchmark design

Taught by

CppNow

Reviews

Start your review of The Best Type Traits that C++ Doesn't Have

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.