( ) (parentheses), 187
ABI (application binary interface), 23–24
Abrahams, David, 280
access
nonexisting element of a std::string, 404
sequence containers, 229
accounts, comparing, 326
accumulate algorithm, 166
acquire-release semantics, singletons, 218
ADL (argument-dependent lookup), 126, 314, 315–316
algorithms, 8
Euclidean, 223
expressing, 304
generic programming, 301, 302. See also generic programming
parallel, 266
preference over raw loops, 201
std::accumulate, 166
std::transform_exclusive_scan, 269
STL (Standard Template Library), 12, 266
aliases
defining, 311
allocation
analysis, enabling code, 448
annotated graphs, 243
application binary interface. See ABI (application binary interface)
code stability, 423
cycles among libraries, 425
expressing reusable parts as libraries, 424–425
argument-dependent lookup. See ADL (argument-dependent lookup)
arguments
functions, 359
metafunctions, 343
Regular type/SemiRegular type, 313–314
template argument deduction, 313
templates, 359
arithmetic
rules, 204
signed/unsigned integers, 204–208
arrays, deleting, 194
artificial scope, 144
assembler instructions, 30
assertions, 443
assignments
copy-assignment operator, 221, 222
pointers, 117
automatic management of devices, 435, 449
automatic memory management, 398. See also memory
automatic type deduction, 179
availability of source code, 376–377
bad functions, example of, 28–29
Bartosz, Milewski, 276
base classes, 101
basic exception safety, 280
behaviors
default, 71
defining, 368
implementation-defined, 9
regular types, 58
undefined, 9, 22, 42, 63, 234–235. See also undefined behaviors
unspecified, 196
big six, 59, 60, 61, 85, 130, 222
binding, late, 114
bit manipulation, 205
block scope, 166
Boost C++ Library, 280
bounds
safety, 439
byte, 409
calculating (at compile time), 339–341
callables
providing, 305
C-arrays
size of, 402
std::array instead of, 401–403
std::vector instead of, 398–400
case-sensitivity, 363
casts
avoiding, 197
naming, 198
Visual Studio compiler, 197
catch-clauses, ordering, 288
catch-fire semantics, 9
catching exceptions, 285–286. See also exceptions
categories
C++ Core Guidelines, enforcing, 447–452
chain operations, 42
characters
arbitrary, 44
character-level input, 411
cheap operations, 33
Clang compiler, 172, 196–197, 219
classes
accessing, 56
base, 101
constructors, 59–60, 66–78. See also constructors
declarations, 431
default operations, 60–66, 88–98
definitions of, 53
explicit actions, 84
functions, 55
implementation, 56
inheritance, 54
initializing, 71
invariant, 55
non-dependent class template members, 323–325
objects, 114–117. See also objects
operators, 117–126. See also operators
overloading, 111
RAII (Resource Acquisition Is Initialization), 140–142
resources, 84
versus struct, 54
classical enumerations, 131, 132. See also enumerations
clients, communication, 281
code. See also performance
enabling analysis, 448
expressing ideas in, 8
expressiveness, 307
generic code based on templates, 10
multi-threaded programs, 232–234
quality of, 167
repetition, 291
reusing, 232
source. See source code
stability, 423
writing, 223
communication
compilers, default operations, 60–66
compile time, 338
complicated expressions, 186
composite type categories, 347–348
lock-free programming, 273–276
conditional execution, 360
versus tasks, 272
without predicates, 257
configuring applied rules, 449
consistency
initialization preferences, 76
const
casts, 199
correctness, 294
functions, 357
variables, 356
enumerations, 133
initializers, 75
introducing, 176
magic, 190
symbolic, 190
metaprogramming, 358
constructors
calling virtual functions, 91–98
conversion, 73
copy, 65
defining, 62
explicit, 121
throwing exceptions, 68
containers, 23
expressing, 305
iterating through, 366
sequence, 229
STL (Standard Template Library), 60, 398–404
context
minimizing dependencies, 320–321
minimizing switching, 261
interfaces, 15–16. See also interfaces
conversions
constructors, 121
decay, 117
implicit conversion operators, 122–124
copy-assignment operator, 63, 221, 222
copy constructors, 65
copying, 42
deep copying, 80
parameters, 34
shallow copying, 80
copy-only type, 221
copy semantics, 12
correctness, type-traits library, 353–354
covariant return type, 103, 104
C-strings, 406
C-style programming, 375
availability of source code, 376–377
entire source code not available, 378–380
cycles
data members
accessing specifiers, 105
non-const, 107
in CppMem, 245
data sharing, concurrency, 257–261
deadlocks, 248
deallocation, resource management, 145–150
decay, 117
declaration
classes, 431
expressions, 168
statements, 168
static_assert, 10
deduction
automatic type, 179
template argument, 311-312
deep copying, 80. See also copying
polymorphic classes, 103
defaults
behaviors, 71
deleting
arrays, 194
destructors, 91
dependencies
avoiding, 390
non-dependent class template members, 323–325
between special member functions, 61
deque, 226
dereferencing pointers, 191–193, 194
design
Gang of Four (GoF), 111
Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, Helm, Johnson, Vlissides), 111
destructors, 145
calling virtual functions, 91–98
deleting, 91
failing, 88
need for, 83
nonvirtual, 87
protected, 87
detection
errors, 10
overflow, 208
deterministic, definition of, 437
devices, automatic management of, 435, 449
discriminated unions, 126
documentation, intention of, 9
don’t repeat yourself. See DRY (don’t repeat yourself)
DRY (don’t repeat yourself), 49, 291, 364, 365
enabling code analysis, 448
ALL_CAPS, 134
constants, 133
enumerator values, 136
strongly typed enums, 131
underlying types, 135
equality operators, 94–96, 97–98
equivalent operations, 124–125
error handling, 279, 280–281. See also errors
errors
with C++ compilers, 377
compilation, 174
compiler, 387
detecting, 10
run-time, 11
SFINAE (Substitution Failure Is Not An Error), 320, 352
static_assert declarations, 10
use-before-set, 177
Euclidean algorithm, 223
evaluation, order of, 150, 194–195, 194–196
exceptions
basic exception safety, 280
dynamic-cast, 116
error handling, 283. See also error handling
ordering catch-clauses, 288
purpose-designed user-defined types, 283–285
safety, 280
strong exception safety, 280
throwing, 68
execution
conditional, 360
metafunctions, 342
policies, 267
selecting, 243
single-threaded, 218
explicit constructors, 121
explicit sharing, minimizing, 236–237
complicated, 186
magic constants, 190
operator precedence, 187
summation with fold, 51
function objects, 307
failing destructors, 88
failure transparency, 280
files
source. See source files
fold expressions, summation with, 51
forward_list, 226
func, 39
function objects
as sorting criteria, 307
with state, 309
ADL (argument-dependent lookup), 126
arguments, 359
classes, 55
constant expressions, 357
constexpr, 29–30, 298, 342, 356
dependencies between special member, 61
helper, 57
invariants for, 15
ISP (interface segregation principle), 100
lambdas, 46
main, 42
members, 56
overloading, 379
parameter packs, 35, 51, 335, 336
passing parameters, 32–38. See also parameters
refactoring, 29
as sorting criteria, 307
specialization of templates, 367–372
struct, 55
unit tests, 18
virtual, 82, 102, 223, 331, 357
virtual clone member, 105
Gang of Four design. See GoF (Gang of Four) design
GCC compiler, 172, 174, 196, 197, 219, 354
general rules. See rules
generic code. See also code
templates, 10
getters, 106
global containers, threads as, 250–251
global scope, 176
global variables, non-const, 16–17
GoF (Gang of Four) design, 111
graphs, annotated, 243
GSL (Guidelines Support Library), 441–444
assertions, 443
guarantees
exceptions, 280. See also exceptions
Guidelines Support Library. See GSL (Guidelines Support Library)
hardware/compiler combinations, 274–276
Haskell, 32
header files, 391
unnamed namespaces, 394
helper functions, 57
#include guard, 388
hiding
implementation details, 310
member functions, 174
hierarchies
classes, 53, 59, 98–117, 331. See also classes
navigating, 115
hints, compilers, 223
IILE (Immediately Invoked Lambda Expression), 183
Immediately Invoked Lambda Expression. See IILE (Immediately Invoked Lambda Expression)
implementation
classes, 56
hiding details, 310
singletons, 18
templates with specializations, 325–330
implementation-defined behavior, 9, 205
implicit conversion operators, 122–124
in-class initializers, 75
inheritance
classes, 54
injection
in-out parameters, 36
in parameters, 34
input/output. See I/O (input/output)
integers, signed/unsigned, 204–208
ABI (application binary interface), 23–24
abstract classes, 101
applying classes, 56
base classes, 101
functions, 27–28. See also functions
multiple inheritance, 111
non-const global variables, 16–17
segregation principle, 100
interface segregation principle. See ISP (interface segregation principle)
invariants
error handling, 282
for functions, 15
I/O (input/output)
character-level input, 411
STL (Standard Template Library), 411–418
stream synchronization, 414–415
ISP (interface segregation principle), 100
iteration
through containers, 366
keep it simple, stupid. See KISS (keep it simple, stupid)
keywords, overriding, 102
KISS (keep it simple, stupid), 59
Koenig lookup, 126, 314, 315–316
lambdas, 46
overloading, 117
as sorting criteria, 307
with state, 310
languages
Haskell, 32
late binding, 114
leaks
memory, 287
resources, 11
libraries, 166. See also STL (Standard Template Library)
Boost C++ Library, 280
cycles among, 425
expressing reusable parts as, 424–425
GSL (Guidelines Support Library), 441–444
reusing code, 232
STL (Standard Template Library). See STL (Standard Template Library)
support, 13
life cycles of objects, 59
lifetimes
objects, 142
safety, 439
linker errors, 387
Linux systems
creation of threads, 262
flushing, 418
size of threads, 261
list, 226
literal type, 224
LoadLoad, 276
local objects, 140, 141, 287. See also objects
lock-free programming, 273–276
locks
mutexes, 264
logical constness, 295
logical structure, expressing, 394
raw, 201
recursion versus, 360
macros
magic constants, 190
management
automatic management of devices, 435, 449
automatic memory management, 398
resources, 139–140. See also resource management
Martin, Robert C., 100
mathematical functions, 32. See also pure functions
member functions, 56
compiler errors, 332
hiding, 174
reserve, 399
shadowing, 112
virtual member function templates, 331–332
members
accessing specifiers for data, 105
declaring, 74
dependencies between special functions, 61
ISP (interface segregation principle), 100
minimizing exposure, 58
non-dependent class template, 323–325
nonpublic, 58
pointers, 85
variables, 75
memory
automatic memory management, 398
leaks, 287
models, 242
ROM (readonly memory), 29
saving, 126
sequence containers, 229
messages
as exceptions and values, 271
metadata, templates, 341
metafunctions, templates, 342–345
constexpr function, 358
templates, 351
meta-rules. See philosophical rules
Metaware compiler, 338
Meyers singleton, 217
Microsoft Visual Studio Compiler, 30
minimizing
context switching, 261
thread creation/destruction, 261–263
time locking mutexes, 264
models, memory, 242
modification versus new value, 359
moving
std::unique_ptr, 153
MSVC compiler, 172
multiple inheritance, 107, 111
multiple mutexes, acquiring, 247–248
multi-threaded programs, 232–234
mutable data, 12
mutexes
locks, 264
MyGuard, 265
Named Return Value Optimization. See NRVO (Named Return Value Optimization)
names
casts, 198
conventions, 342
mangling, 380
similar names, 170
namespaces, 57
defining overloaded operators, 125–126
nested scopes, reusing names, 172–175
NNM (No Naked Mutex), 246
destructors, 88
function definition, 88
no exception safety, 280
no-leak guarantee, 280
No Naked Mutex. See NNM (No Naked Mutex)
No Naked New. See NNN (No Naked New)
non-const data members, 107
non-const global variables, 16–17
non-dependent class template members, 323–325
nongeneric code, writing, 365–367
nonpublic members, 58
nonvirtual, destructors, 87
normal parameter passing, 32
no-throw guarantees, 280
notifications
with tasks, 273
NRVO (Named Return Value Optimization), 36, 37
NULL, 192
nullptr, 191–193, 192–193. See also pointers
objects
constructors creating, 67
creating, 145
function objects. See function objects
immutable data and, 294
life cycles of, 59
lifetimes, 142
moving, 80
ODR (One Definition Rule), 385
One Definition Rule. See ODR (One Definition Rule)
operands, defining overloaded operators, 125–126
operations
cheap, 33
passing to algorithms, 305–307
reordering, 276
operators
ADL (argument-dependent lookup), 126
precedence, 187
optimization, 17
code, 167
wrong, 214
order of evaluation, expressions, 194–195
out parameter, 52
overflow, 208
overloading, 49
ADL (argument-dependent lookup), 126
classes, 111
functions, 379
implicit conversion operators, 122–124
override, 102
ownership
pointers/references, 143, 442–443
packing parameters, 35
parallelism, concurrency and, 232, 266–269
parameters
in, 34
in-out, 36
normal parameter passing, 32
out, 52
Parent, Sean, 167
parentheses ( ), 187
passing
pointers, 297
references, 297
normal parameter passing, 32
performance, 213
enabling optimization, 218–229
function objects, 307
measurements, 214
Meyers singleton, 217
wrong optimizations, 214
philosophical rules, 7
compile-time checking, 10
expressing ideas in code, 8
expressing intent, 9
immutable data, 12
resource leaks, 11
run-time checking, 11
run-time errors, 11
statically type safe programs, 10
supporting tools, 13
support libraries, 13
writing in ISO standard C++, 8–9
physical constness, 295
Pikus, Fedor, 274
Plain Old Data. See POD (Plain Old Data)
POD (Plain Old Data), 33
assigning, 117
members, 85
rules, 191
polymorphic classes, 81–83, 103
portably enforceable, definition of, 437
POSIX Threads, 256
postconditions, 15
power as function/metafunction, 345
pragma once, 388
preconditions, 15
predicates, condition variables without, 257
Preshing, Jeff, 276
primary type categories, 346–349
principle of least astonishment, 118
Pro.boundsBounds safety, 439
Pro.lifetimeLifetime safety, 439
Pro.typeType safety, 438
programming
C-style, 375. See also C-style programming
generic. See generic programming
metaprogramming, 336–356, 351, 358. See also metaprogramming
programs
statically type safe, 10
protected destructors, 87
pure functions, 31–32. See also functions
purpose-designed user-defined types, 283–285
quality of code, 167
race conditions, 253
RAII (Resource Acquisition Is Initialization), 140–142, 246, 264, 287, 288, 289
ranges, expressing, 305
raw loops, 201
raw references, 143
read-only memory. See ROM (read-only memory)
recursion versus loop, 360
passing, 297
raw, 143
SemiRegular type, 315
universal, 334
referential transparency, 31
relations, enabling, 243
relaxed semantics, 275
reordering operations, 276
repetition of code, 291
reserve function, 399
Resource Acquisition Is Initialization. See RAII (Resource Acquisition Is Initialization)
resources
leaks, 11
ownership of, 39
return-statements in functions, 428–429
Return Value Optimization. See RVO (Return Value Optimization)
return values
metafunctions, 343
simulations, 361
reusing
expressing reusable parts as libraries, 424–425
ROM (read-only memory), 29
rule of six, 61
rule of zero, 60
rules
arithmetic, 204
configuring applied, 449
NNN (No Naked New), 147
ODR (One Definition Rule), 385
philosophical, 7. See also philosophical rules
pointers, 191
user-defined types, 53
running code analysis, 449
run time
calculating at, 343
constant expression in ROM, 29–30
errors, 11
RVO (Return Value Optimization), 36, 37
safety
basic exception, 280
bounds, 439
exceptions, 280
lifetimes, 439
types, 438
scopes
block, 166
global, 176
sizes, 168
semantics
acquire-release, 218
catch-fire, 9
copy, 65
copy-only type, 221
relaxed, 275
sequence containers, 229
sequential consistency, 218, 243, 274, 275
setters, 106
SFINAE (Substitution Failure Is Not An Error), 320, 352
shallow copying, 80. See also copying
signed/unsigned integers, 204–208
SIMD (Single Instruction, Multiple Data), 267
similar names, 170. See also naming
simulations, return values, 361
single-argument constructors, 72–74
Single Instruction, Multiple Data. See SIMD (Single Instruction, Multiple Data)
single return-statements in functions, 428–429
single-threaded case, 218
six, rule of, 61
sizes
of C-arrays, 402
of chars with C++ compilers, 377
of enumerators, 136
of scopes, 168
of threads, 261
slicing, 81
cycles of, 154
as function parameters, 156
lifetime semantics of, 157–159
sharing ownership, 261
software units, 281
source code
entire code not available, 378–380
specialization,
templates, 360
special member functions, 61
specifications, exceptions, 287–288
spurious wakeups, 256
stability, code, 423
Standard Template Library. See STL (Standard Template Library)
state, function objects, 308–310
statements, 165–166, 199. See also declarations
definitions of, 166
initializing variables, 175–184
return-statements in functions, 428–429
statically type safe programs, 10
static_assert declarations, 10
std::forward, 144, 198, 226, 334
std::make_unique, 36, 148, 153, 334, 335
std::unique_ptr, 140, 146–147, 150–151
moving, 152
STL (Standard Template Library), 8, 21, 305, 397
expressions, 166
RAII (Resource Acquisition Is Initialization), 140–142
strings, 410
streams
strings
accessing nonexisting element of, 404
owning character sequences, 405–406
STL (Standard Template Library), 410
string_view, referring to character sequences, 407–408
strong exception safety, 280
strongly typed enums, 131
Stroustrup, Bjarne, 169
struct, 55
case-sensitivity, 363
class versus, 54
structures, organizing data into, 54–55
Substitution Failure Is Not An Error. See SFINAE (Substitution Failure Is Not An Error)
suffixes, .cpp, 384
summation
with fold expressions, 51
with va_arg, 51
support
libraries, 13
tools, 13
symbolic constants, 190
synchronization, 255
volatile for, 238
tasks
condition variables versus, 272
notifications with, 273
Technical Report on C++ Performance, 430
argument deduction, 313
arguments, 359
function objects. See function objects
function template specialization, 367–372
generic code, 10
implementations with specializations, 325–330
instantiation, 338
metadata, 341
metaprogramming, 336–356, 351. See also metaprogramming
parameter packs, 35, 51, 335, 336
specialization, 360
STL (Standard Template Library), 8
virtual member function, 331–332
termination characters, 405, 406
testability, 16
text
STL (Standard Template Library), 404–411
types of, 405
threads
detaching, 253
joining, 250
POSIX Threads, 256
sizes of, 261
throwing exceptions, 68
throwing functions, 30–31. See also functions
tools, 238
supporting, 13
transform_exclusive_scan algorithm, 269
transparency, referential, 31
troubleshooting throwing exceptions, 288–291
two-phase initializations, 431–433
typedef, defining aliases, 311
types
automatic type deduction, 179
copy-only, 221
literal, 224
manipulation at compile time, 340–341
purpose-designed user-defined, 283–285
safety, 438
of text, 405
underlying, 135
unsigned, 205
metaprogramming, 351
Uncle Bob, 100
undefined behaviors, 9, 22, 42, 63
core dumps, 146
C-strings, 405
naked unions, 127
printf function, 414
underflow, 208. See also overflow
underlying types, 135
discriminated, 126
naked, 127
unit tests, 18
universal references, 334
unknown code, calling, 249–250
unnamed namespaces, 394
unpacking parameters, 35
unsigned/signed integers, 204–208
unspecified behavior, 196
use-before-set error, 177
user-defined types
rules, 53
using
defining aliases, 311
utilities. See libraries; tools
values
enumerations. See enumerations
enumerator, 136
return, 343
Van Eerd, Tony, 274
variables
categories of, 235
condition, 254–257. See also condition variables
constant expressions, 356
declaring, 57
global, 16–17. See also global variables
introducing, 176
member, 74
mutable, 296
vectorization, 267
virtual clone member function, 105
virtual functions, 102
clone, 105
default arguments, 113-114
reasons for, 105
virtual member function templates, 331–332
visibility, modifying, 175
Visual Studio
casts, 197
enforcing C++ Core Guidelines, 448–450
volatile for synchronization, 238
wakeups
lost, 255
spurious, 256
warnings with C compilers, 376
Windows systems
creation of threads, 262
flushing, 418
size of threads, 261
writing
code, 223
wrong optimizations, 214
YAGNI (you aren’t gonna need it), 424
The Zen of Python, 198, 364, 365
zero. See also arithmetic
dividing by, 210
rule of, 60