Collections of notes, books
- CPP / C++ Notes - C++ Shrine (HTML version)
- C++ Core Guidelines (HTML version)
- The Definitive C++ Book Guide and List)
- Mastering Modular Programming: A Comprehensive Guide To C++ Separate Compilation
Language
See also The Definitive C++ Book Guide and List.
- Bit field
- How C++14 and C++17 help to write faster (and better) code. Real world examples
- Value semantics
- C++ value categories and decltype demystified
- Argument Dependent Lookup
- C++17: fold expressions
- C++17: if constexpr
- C++17: structured bindings
- C++17: lambdas are permitted in constant expressions
- C++20: std::is_constant_evaluated()
Best practices
- The C++ Super FAQ
- Collaborative Collection of C++ Best Practices
- Library Coding Style
- Stop using out arguments
- Want Speed? Pass by Value.
- Advantages of pass-by-value and std::move over pass-by-reference
- (C language) Why size_t matters
Idioms
Boost: Generic Programming Techniques
- Tag dispatching: Tag Dispatching by Type, Tag Dispatching and Inheritance
- Run-time selection in OpenFOAM (implementation of a „virtual constructor“ or „Factory Method of initialization“):
Templates
- Wikibooks: Template Meta-Programming
- Solving FizzBuzz using compiler error messages
- Wikibooks: Expression-template
- Faster Vector Math Using Templates (expression templates example)
- template instantiation: http://stackoverflow.com/a/8752879/4180822
- How to separate definition from the declaration for a class template using ‚extern‘ in C++11 in a library (dll, so,..)
- Simulate static_if with C++11/C++14
- Replacing virtual methods with templates
Linkage categories
- inline keyword does not imply inlining
- Superiority of unnamed namespace over static
- Anonymous namespaces are not sufficient replacement for namespace-static
Strangeness
- Bit Twiddling Hacks
- about
std::vector<bool>
: http://www.gotw.ca/gotw/050.htm - Inheritance – What your mother never told you
- before C++17, constexpr static members have to be defined outside of the class:
- https://stackoverflow.com/questions/39646958/constexpr-static-member-before-after-c17
- the unary „+“ can be used as a workaround to avoid an odr-use of undefined static data member: https://stackoverflow.com/questions/272900/undefined-reference-to-static-class-member/272996#272996
- type punning, strict aliasing:
- function overloading:
- A conditional copy constructor
- Passing a multidimensional variable length array to a function (a standard C99 feature which is not in C++)
- C++14: return …; vs return (…);
- Does a const reference class member prolong the life of a temporary?
- Use of rvalue reference members?
Compilers, profilers, debuggers
- C++ support in clang
- clang: Expressive Diagnostics (note the section on „Template Type Diffing“)
- clang tools:
- code formatting:
- PGI: http://www.pgroup.com/products/
- HCC: https://www.amd.com/en/press-releases/boltzmann-initiative-2015nov16 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0069r0.pdf https://github.com/RadeonOpenCompute/hcc/wiki
- Templight 2.0 - Template Instantiation Profiler and Debugger https://github.com/mikael-s-persson/templight https://github.com/mikael-s-persson/templight-tools
- orbit – C/C++ performance profiler by Google
Linkers and loaders
- Beginner‘s Guide to Linkers
- Why does the order of
-l
options in GCC matter? - Static and dynamic linking with GCC
Stack backtracing
- http://www.linuxjournal.com/article/6391
- https://www.gnu.org/software/libc/manual/html_node/Backtraces.html
- https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html
- http://panthema.net/2008/0901-stacktrace-demangled/
- http://stackoverflow.com/a/1925461/4180822
Optimizations
- Latency numbers every programmer should know (2012)
- Why can lambdas be better optimized by the compiler than plain functions?
- cache optimizations:
- alignment:
- operator new before C++17 may not support over-aligned types, see https://stackoverflow.com/a/53485295
- over-aligned class members may become misaligned in derived classes, see https://stackoverflow.com/a/46475498
- Eigen has
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
: http://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html - clang:
- const keyword is for compilation checking of the program semantics, not for optimization
- Polly: LLVM Framework for High-Level Loop and Data-Locality Optimizations
asembler https://en.wikipedia.org/wiki/X86_instruction_listings
Multithreading
- (Not) using std::thread
- The promises and challenges of std::async task-based parallelism in C++11
- Implementations of std::async and how they might Affect Applications
- Multithreading in C++0x part 6: Lazy initialization and double-checked locking with atomics
- madthreading: A low-overhead, task-based threading API using a pool of C++11 threads
- How to write a CAS loop using std::atomic
Thread pool implementations
- https://github.com/mtrebi/thread-pool (C++11, with a nice explanation)
- https://github.com/Ethan13310/Thread-Pool-Cpp (C++14, very lightweight)
- https://github.com/d36u9/async (C++14, high-performance, unbounded MPMC (multi-producer multi-consumer) lock-free queue)
Data structures
std::map
andstd::set
are very slow, but evenstd::unordered_map
andstd::unordered_set
are slow since they use linked lists for chaining. An alternative: open addressing strategy, e.g. the cuckoo hashing (available in libcuckoo), or the hopscotch hashing (available in hopscotch-map).- Swiss Tables and absl::Hash
- strings <-> enums: http://stackoverflow.com/questions/28828957/enum-to-string-in-modern-c-and-future-c17-c20