Tag: C++11
40 posts
-
C++ enum class: Scoped Enums, Underlying Types, Exhaustive switch, and Stable Serialized Values
Strongly typed scoped enums in C++11 and later: no implicit int conversion, explicit underlying types, switch exhaustiveness warnings that actually fire, type-safe bit flags, and keeping stored enum values stable.
-
C++ Lambda Capture: By Value, By Reference, Init Capture, and the Lifetime Bugs Each One Invites
How C++ lambda captures really work: copies taken at creation time, [=] silently capturing this, mutable state duplicated by std::function, move-only captures, and dangling references.
-
C++ Mutex & Lock — Mutual Exclusion and lock_guard
C++ mutex and locks: std::mutex, lock_guard, unique_lock, std::lock, scoped_lock, recursive_mutex, timed_mutex, and avoiding deadlocks.
-
C++ Range-Based for: auto, References, and Temporaries
Range-based for in C++: auto vs auto& vs const auto&, proxy iterators, temporaries, C++17 structured bindings, custom begin/end, and production patterns.
-
Range-Based for Loop Errors in C++: Missing begin()/end() and Eight Other Pitfalls
Fix C++ range-for errors: "begin was not declared in this scope", const begin(), vector<bool> proxies, decayed arrays, map pair copies and dangling temporaries.
-
C++ auto Type Deduction Errors
Fix C++ auto type deduction issues: why references and const drop, when to use auto& and auto&&, eight common compiler errors, and AAA-style guidelines.
-
C++ nullptr vs NULL: The Overload Bug NULL Causes and What std::nullptr_t Fixes
Why C++11 replaced NULL and 0 with nullptr: the overload bug NULL causes, what std::nullptr_t is, nullptr in templates and APIs, and migrating old code.
-
std::call_once and once_flag: Thread-Safe One-Time Initialization vs static Locals
std::call_once is a C++11 function that guarantees a function executes exactly once, even when called from multiple threads.
-
Modern C++ Syntax Cheatsheet: C++11 to C++20 Features and Their Pitfalls
Scannable modern C++ reference: each C++11/14/17/20 feature with the standard that added it, a snippet verified on g++ 10.3, and the pitfall that bites.
-
C++ Attributes: nodiscard, deprecated, maybe_unused, likely, fallthrough and noreturn
What each standard C++ attribute actually does, the exact GCC warnings it triggers, and the traps: nodiscard gaps, misused likely, noreturn that returns.
-
Variadic Templates in C++: Parameter Packs, Pack Expansion, sizeof... and Fold Expressions
C++ variadic templates explained: parameter packs, where pack expansion is allowed, recursion vs fold expressions, empty packs, and the errors you will hit.
-
C++ User-Defined Literals: Raw vs Cooked Operators, Unit Types and consteval Validation
How C++ picks a literal operator, why suffixes need an underscore, raw vs cooked forms, unit types, and consteval literals that reject typos at build time.
-
C++ Value Initialization: What Empty () and {} Do for Scalars and Classes
Value initialization uses empty () or {}. Scalars become zero-like; classes call the default constructor.
-
C++ Brace Initialization: Narrowing Checks, Most Vexing Parse and initializer_list
What C++11 brace initialization really buys you: narrowing errors, no Most Vexing Parse, and the initializer_list rules that make vector<int>{10} one element.
-
C++ chrono::time_point: Clocks, Epochs, Timeouts, and Elapsed Time
How std::chrono::time_point ties a duration to a clock, steady_clock vs system_clock, time_point_cast, and timeouts, timestamps and elapsed-time measurement.
-
std::tuple, tie and Structured Bindings: Returning Multiple Values in C++
Using std::tuple in C++: make_tuple vs CTAD, std::get, tie and ignore, lexicographic comparison, map keys, reference traps, and when a named struct is better.
-
thread_local in C++: Per-Thread Caches and RNGs, Initialization Order and Pitfalls
C++11 thread_local: per-thread storage, caches, RNGs, initialization, and patterns without shared mutex overhead.
-
steady_clock vs system_clock vs high_resolution_clock: Measuring Elapsed Time and Timeouts
When to use steady_clock vs system_clock in C++, why high_resolution_clock is system_clock on GCC, and how to time code and timeouts correctly.
-
What Is C++? History, Standards , Use Cases, and How to
C++ overview for beginners: evolution from C, C++11/17/20/23, game/systems/finance use cases, pros and cons, myths, learning roadmap, and production.
-
C++ random | Engines, distributions, and replacing rand()
C++11 random: random_device seeding, mt19937, uniform and normal distributions, shuffle, weighted picks, threading, and when to use a cryptographic RNG.
-
C++ std::random_device | Hardware entropy for seeding
How random_device maps to OS entropy, using entropy(), seed_seq for mt19937, UUID and token examples, performance vs mt19937.
-
C++ Random Numbers in Practice: Seeding, Reproducibility, and Common Pitfalls
Practical C++ <random> pitfalls: why rand() % n is biased, why one 32-bit seed is not enough for mt19937, why the same seed gives different numbers on different compilers, and when you need a CSPRNG instead.
-
C++ sregex_iterator | Regex iterators for all matches
Use sregex_iterator and sregex_token_iterator to enumerate matches, split tokens, avoid dangling iterators, and handle empty matches and UTF-8 limits.
-
C++ packaged_task: Deferred Tasks, Futures, and Thread Pools
std::packaged_task is a C++11 feature that wraps a function or callable object and allows you to receive the result as a std::future.
-
C++ override & final: Virtual Overrides and Devirtualization
C++ override and final: catching signature mistakes, sealing classes and virtual functions, devirtualization and performance notes, and practical.
-
C++ Move Constructor: rvalue Stealing & noexcept Best
C++ move constructors: rvalue resource transfer, copy vs move, vector and noexcept, self-move, and when not to std::move return locals.
-
C++ noexcept Specifier: Contracts, Moves, and std::terminate
How noexcept actually changes program behavior: why a violated noexcept promise skips exception handling entirely and calls std::terminate, and why vector silently falls back to copying without a noexcept move constructor.
-
C++ initializer_list Constructors: Why Braces Pick Them, and How That Breaks Overloads
How std::initializer_list constructors take priority in brace initialization, why vector{3, 7} has two elements, {{}} vs ({}), move-only elements, dangling lists, and API design rules.
-
C++ inline Namespace: Versioning, API Evolution, and ADL
How C++11 inline namespaces lift names into the parent, why the version stays in mangled symbols, and how lookup, specialization and ADL treat them.
-
C++ Random Distributions: Choosing and Using uniform, normal, Poisson, and discrete
C++11 random distributions explained by what they model: uniform, normal, Bernoulli, binomial, Poisson, exponential, and discrete, plus range rules, reset(), per-call parameters, and the modeling mistakes that skew simulations.
-
C++ decltype: Why decltype((x)) Is a Reference and decltype(auto) Can Dangle
How decltype computes types: names vs expressions, value categories, trailing return types, dangling decltype(auto) returns with the real GCC warning.
-
C++ =default and =delete: Triviality, Deleted Overloads, and the Implicit Move Trap
Why =default on first declaration keeps a type trivial, how =delete blocks conversions, and why declaring a destructor silently turns your moves into copies.
-
C++ constexpr Functions: Compile-Time Evaluation Rules from C++11 to C++17
C++ constexpr functions: compile-time and runtime use, C++11 vs C++14 vs C++17, arrays, classes, and optimization. Practical examples and pitfalls.
-
std::function vs Function Pointers vs Template Callables in C++: Type Erasure Cost, SBO and C Interop
std::function vs function pointer vs template in C++: why capturing lambdas cannot convert, when std::function allocates, move-only captures, C void* data.
-
C++ std::atomic: Atomic Operations, Memory Order, and compare_exchange
How std::atomic prevents data races in C++: load/store/fetch_add, compare_exchange_weak vs strong, the memory orders relaxed, acquire/release and seq_cst, and when a mutex is still the better tool.
-
C++ std::bind: Placeholders, Partial Application, and When a Lambda Is Better
std::bind is a function introduced in C++11 that creates a new function object by pre-binding a function and its arguments.
-
C++ std::chrono::duration: Units, Literals, and Safe Conversions
Working with std::chrono::duration in C++ - representing time intervals, chrono literals like 500ms and 2h, converting between units safely, C++20 calendar literals, and avoiding truncation bugs.
-
C++ explicit: Blocking Implicit Conversions, explicit operator bool, and C++20 explicit(bool)
How explicit blocks implicit conversions via one-argument constructors and conversion operators, why explicit operator bool works in if, and C++20 explicit(bool).
-
std::async and Launch Policies: When async Actually Runs on Another Thread
What std::launch::async and deferred really do, why the default policy breaks wait_for loops, why the returned future blocks in its destructor, and exceptions.
-
How C++ auto Deduces Types: References, const, Braced Init and decltype(auto)
How C++ auto deduces types: why it drops const and references, auto& vs auto&&, braced-init rules, vector<bool> proxies, decltype(auto) and real errors.