149 terms across 10 categories
` is the standard header of iterator-based algorithms: find, sort, copy, count, transform, and dozens more. You pass [first, last) iterators and often a predicate or output iterator. C++20 adds the same names under std::ranges`.
Backtracking is a depth-first search over a tree of partial solutions. You add a choice, recurse, then undo the choice so the next sibling can try a different one. Pruning skips branches that cannot beat the constraints.
Breadth-first search visits a graph level by level: all nodes at distance 0, then 1, then 2. A queue holds the frontier. On an unweighted graph, the first time you reach a node is a shortest path.
Depth-first search walks a graph by going as deep as possible along one path before backtracking. It is implemented with recursion or an explicit stack. It finds cycles, topological order, connected components, and paths; it does not find unweighted shortest paths.
Dynamic programming solves a problem by combining answers to overlapping subproblems, storing each subproblem's result once. Recursion without a table repeats work and often becomes exponential; a table makes it polynomial.
A greedy algorithm builds a solution by taking the locally best choice at each step and never retracting it. It is fast when a proof says those choices compose into a global optimum. Without a proof it is a heuristic.
A prefix sum array stores at index i the sum of the first i elements (or first i+1, depending on convention). Any range sum a[l] + … + a[r] then becomes one subtraction: pref[r+1] - pref[l].
Recursion is a function calling itself with a smaller or simpler argument until a base case returns without another call. Each call pushes a stack frame. C++ does not guarantee that a tail call will reuse the frame.
A sliding window maintains a contiguous slice of a sequence as two ends move only forward. Each element enters and leaves the window at most once, so a class of subarray problems that look O(n²) become O(n).
Space complexity is how extra memory an algorithm uses as the input size n grows. It counts auxiliary storage, not the input itself, unless we say "total space". Recursion uses stack space; vector copies use heap space.
std::binary_search reports whether a sorted range contains a value. It is O(log n) on random-access iterators. It returns a bool, not a position; use lower_bound when you need the iterator.
std::find scans a range for the first element that equals a value. std::find_if uses a predicate. Both are O(n) and return end when nothing matches. They need only input iterators.
std::lower_bound returns an iterator to the first element in a sorted range that is not less than a value. If every element is less, it returns end. That iterator is the insertion point that keeps the range sorted.
std::nth_element rearranges a random-access range so the element at nth is the one that would be there after a full sort. Every element before nth is not greater than it; every element after is not less. Average time is O(n).
std::sort rearranges a random-access range into non-decreasing order. It is O(n log n) and not stable: equal elements may change relative order. Pass a comparator to sort by something other than operator<.
std::stable_sort sorts a random-access range and keeps the relative order of equal elements. It is typically a merge sort: O(n log n) time and, if it can allocate, O(n) extra memory. Use it when you sort by one key and then another.
Time complexity is how the number of steps in an algorithm grows as the input size n grows. We write it in Big-O: std::find on a vector is O(n), std::sort is O(n log n), map lookup is O(log n).
Two pointers is a technique that walks a sequence with two indices (or iterators) instead of nested loops. The pointers move inward, forward together, or at different speeds, turning many O(n²) pair searches into O(n).
An abstract class is a class you cannot instantiate because it has at least one pure virtual function. It exists to be a base: it names a contract, and derived classes provide the missing operations.
public, protected, and private control which names of a class other code can use. They are a compile-time check. They do not hide the data in the compiled binary and they do not affect layout beyond the order you already wrote the members.
A class is a user-defined type that bundles data together with the functions allowed to operate on that data. Keeping the data private lets the class guarantee facts about itself that no outside code can break.
A constructor is the member function that turns raw storage into a usable object by establishing the class invariant. It has the class's name, no return type, and runs exactly once per object, before the object's lifetime begins.
Copy assignment replaces an existing object's value with a copy of another object of the same type. It is T& operator=(const T&). Unlike the copy constructor, the left-hand side already has a lifetime and must release its old resources first.
The copy constructor creates a new object as a copy of an existing one of the same type. Its signature is T(const T&) (or T(T&)). It runs for T b = a;, pass-by-value, and return-by-value when a move or elision does not apply.
CRTP is the curiously recurring template pattern: a base class template takes the derived class as its parameter, template struct Base { ... }; class Derived : public Base. The base can call derived methods as static, inlined calls with no vtable.
A destructor is the member function that runs when an object's lifetime ends. It has the name ~Class, takes no arguments, and is where the object releases what it owns.
friend grants a function or another class access to a class's private and protected names. Friendship is not inherited, not mutual, and not transitive. It is a targeted hole in encapsulation.
Inheritance builds one class on top of another: the derived class starts with a complete copy of the base class's members. With public inheritance it is also substitutable for the base, which is what runtime polymorphism needs.
A member initializer list is the : name_(name), size_(size) clause between a constructor's signature and its body. It constructs each member directly with the value you want, instead of default-constructing it and then assigning over it.
Move assignment replaces an existing object's value by stealing resources from an expiring object of the same type. It is T& operator=(T&&). The left-hand side must release what it already owns; the right-hand side is left in a valid empty state.
The move constructor builds a new object by stealing resources from an expiring object of the same type. Its signature is T(T&&). After it runs, the source is still a live object, but its value is unspecified and safe only to assign to or destroy.
Move semantics is the language feature that transfers resources from an expiring object instead of copying them. It is built from rvalue references, move constructors, move assignment, and std::move. The source stays alive in a valid empty-ish state.
Multiple inheritance lets a class list more than one base: class D : public A, public B. D contains both bases' subobjects. The diamond problem appears when two bases share a grandparent; virtual bases merge that grandparent into one.
An object is a concrete instance of a type: it has a type, a storage location, and a lifetime. Touching it before its lifetime starts or after it ends is undefined behavior, whatever the pointer still says.
Operator overloading lets a class define what +, ==, [], << and other operators mean for its objects. The call a + b becomes operator+(a, b) or a.operator+(b). Precedence does not change.
PIMPL (pointer to implementation) hides a class's private data behind a pointer to an incomplete type defined in the .cpp file. The header stays stable when the internals change, so callers do not recompile.
Polymorphism means the same call or the same algorithm works on more than one type. C++ has compile-time polymorphism (templates, overloads) and runtime polymorphism (virtual functions). They solve different problems and cost different things.
A pure virtual function is a virtual function declared with = 0. The class that contains it is abstract: you cannot construct an object of that type. A derived class must override the function, or it stays abstract too.
std::move(x) is a cast that turns x into an rvalue. It does not move anything by itself. It makes overload resolution pick a move constructor or move assignment if one exists, so the next use of x is allowed to steal from it.
A virtual function is dispatched on the object's dynamic type, not on the type of the pointer or reference you call through. base->draw() runs Circle::draw if the object is a Circle and draw was declared virtual in Shape.
A vtable is the per-type table of function pointers the compiler builds for a class that has virtual functions. Each object of that class stores a hidden pointer (the vptr) to the table. A virtual call loads the slot and jumps.
An adapter translates one interface into another so existing code can talk to a type it was not written for. In C++ that is a wrapper class, a set of free functions, or a std::queue over a deque.
A decorator implements the same interface as the object it wraps and adds behaviour before or after forwarding. You stack decorators without changing the wrapped type or the caller's static type.
A factory is a function (or type) that creates objects so callers do not write new or name a concrete class. In C++ it should return ownership: std::unique_ptr, not a raw pointer.
The observer pattern lets many listeners react when a subject changes. In C++ that is a list of callbacks (std::function, a virtual Listener, or a signal library). The hard part is lifetime: a listener must not be called after it dies.
PIMPL as a design pattern is the choice to hide a class's implementation behind an opaque pointer so the public header stays stable. It is the same mechanism as the pimpl OOP entry, described here as an architectural habit rather than a language feature.
RAII as a design pattern is the rule that every resource is owned by an object whose destructor releases it. Locks, files, sockets, and memory all follow the same shape. The language feature is destructors; the pattern is applying them to every acquire/release pair.
A singleton is a type that has exactly one instance for the process (or the thread). In C++ the usual form is a function-local static, which is initialised once and is thread-safe since C++11. Prefer passing dependencies over a hidden global.
Strategy packages an algorithm behind a common interface so you can swap it at compile time or run time. In C++ that is a virtual compare, a template policy parameter, or a std::function / lambda you pass into std::sort.
Type erasure stores different types behind one named type by hiding the concrete type in a heap (or small-buffer) object with a virtual or function-pointer vtable. std::function, std::any, and std::shared_ptr with a custom deleter are the standard erasers.
An allocator is an object that containers ask for raw memory. std::allocator calls operator new. A custom allocator can serve a pool, an arena, or a tracking heap. C++17 std::pmr is the usual way to swap allocators without rewriting container types.
Copy elision is when the compiler constructs an object directly in its final location and skips a copy or move that the abstract machine described. Since C++17, some elisions are mandatory. Named return value optimisation (NRVO) is still optional.
A dangling reference (or dangling pointer) names storage whose lifetime has ended. Reading or writing through it is undefined behaviour. Locals that went out of scope, deleted heap, and invalidated vector iterators are the usual sources.
new T allocates storage and constructs a T. delete p destroys the object and frees the storage. new T[n] and delete[] p are the array forms. Prefer std::make_unique over bare new in application code.
Placement new constructs an object in storage you already have: new (ptr) T(args). It does not allocate. You end the lifetime with an explicit destructor call ptr->~T(), not with delete.
RAII ties a resource to the lifetime of an object. The constructor acquires the resource, the destructor releases it, so cleanup happens automatically when the object goes out of scope.
If you write one of the special member functions, you should write or delete all of them that the class needs. Three is destructor plus copy constructor plus copy assignment. Five adds move constructor and move assignment. Zero is the goal: members manage themselves, so you write none.
std::shared_ptr is a smart pointer with shared ownership. A control block holds a reference count. The last shared_ptr to die deletes the object. Copies increment the count; destruction decrements it.
The stack holds automatic objects: locals and parameters whose lifetime ends when the scope ends. The heap holds dynamic objects: memory you get from new, malloc, or an allocator, whose lifetime ends when you release it. C++ objects can live in either place.
std::make_unique(args...) allocates a T with new and returns a std::unique_ptr that owns it. It is the default way to create a unique pointer. make_unique(n) creates an array.
std::unique_ptr is a move-only smart pointer that owns a heap object. When the unique_ptr dies, it deletes the object. There is no shared ownership and no reference count.
std::weak_ptr observes an object owned by shared_ptr without keeping it alive. lock() tries to promote to a shared_ptr; if the object is already gone, you get an empty shared_ptr.
A test assertion checks that a condition holds and records a failure if it does not. GoogleTest uses EXPECT_ / ASSERT_. Catch2 uses CHECK / REQUIRE. ` assert` is a debug runtime check, not a test reporter.
Catch2 is a C++ test framework that uses TEST_CASE and REQUIRE/CHECK macros. Assertions are ordinary C++ expressions: REQUIRE(add(2, 2) == 4). Sections nest inside a test case to share setup without a fixture class.
A death test checks that a statement aborts the process: abort, exit, an uncaught exception that calls terminate, or a signal. GoogleTest runs the statement in a child process and looks at the exit status and stderr.
A fixture is shared setup and teardown for a group of tests: a temp directory, a parsed config, a fake clock. In GoogleTest that is a class with SetUp/TearDown used by TEST_F. In Catch2 it is often a SECTION or a RAII object at the top of a TEST_CASE.
GoogleTest (gtest) is the most common C++ unit-test framework. You write TEST and TEST_F macros, assert with EXPECT_ and ASSERT_, and run a binary that the library's main drives.
A mock is a test double you configure with expected calls and return values. In C++ that usually means a virtual interface plus gMock (MOCK_METHOD). Prefer a hand-written fake when the interaction is simple.
auto asks the compiler to deduce a variable's type from its initialiser. auto n = 3; is int. auto is not a dynamic type: the type is fixed at compile time, just not spelled by you.
A capture is how a lambda reaches variables from the enclosing scope. [x] copies x into the closure, [&x] stores a reference, [=] copies everything used, [&] references everything used. Captures are initialised when the lambda is created, not when it is called.
A cast is an explicit conversion. C++ has four named casts — static_cast, dynamic_cast, const_cast, reinterpret_cast — plus the function-style and C-style casts you should not write in new code. Each named cast says why the conversion is allowed.
Turning C++ source into a program happens in two separate stages: the compiler translates each source file independently into an object file, then the linker stitches those object files together and resolves the names they refer to.
A concept is a named, compile-time predicate on types, added in C++20. Attaching one to a template says what the template requires, so the compiler rejects bad arguments at the call site with a readable message.
Conditionals choose which statements run. if / else tests a boolean condition. switch matches an integer or enumeration against a list of constant cases. Both decide control flow; they do not produce a value unless you use C++20's if with an initialiser or assign inside the branches.
const means this object will not be mutated through this name after initialisation. constexpr means the value (or the function) can be evaluated at compile time, so you can use it as an array bound, a template argument, or a constant expression.
consteval marks a function that must run at compile time; a runtime call is a hard error. constinit marks a static-duration variable that must be initialised before the program starts, without making the variable itself const.
decltype(expr) is the type of expr, including references and const, without evaluating expr. Use it when auto's drop-ref rules would throw away the part of the type you need.
A default argument gives a parameter a fallback value that the compiler fills in when the caller omits it. Only trailing parameters can have defaults, and the default belongs in the declaration the caller can see.
enum class is a scoped enumeration. Its enumerators live inside the type's name (Color::Red), do not convert silently to int, and can pick an explicit underlying integer type.
Exceptions are a control-flow path for failures that the immediate caller cannot handle. throw starts stack unwinding; destructors of local objects run; the first matching catch handles the object that was thrown.
Overloading lets several functions share a name if their parameter lists differ. The compiler picks one at the call site by comparing argument types to each candidate. The return type is not part of that choice.
A function is a named block of code you can call with arguments. It has a return type, a name, a parameter list, and a body. The declaration tells callers the signature; the definition supplies the body the linker will find.
A header file publishes what a component offers — the declarations other code needs to compile against. A source file supplies the bodies. Splitting them keeps rebuilds small and keeps the one-definition rule satisfied.
An include guard stops a header's contents from being pasted into the same translation unit more than once. The classic form is an #ifndef/#define/#endif wrapper; #pragma once is the shorter non-standard equivalent.
A lambda is an anonymous function you write at the call site. The compiler turns it into a unique class with operator(), so you can pass behaviour into std::sort, std::find_if, or a thread without naming a function.
Loops repeat a block while a condition holds. C++ has while, do/while, the C-style for, and range-for. break leaves the loop; continue skips to the next iteration.
An lvalue is an expression that names a durable object you can take the address of. An rvalue is a temporary or a value that is about to expire, which is why std::move and move constructors talk to rvalues and leave lvalues alone.
A namespace is a named scope for declarations. It lets two libraries both define a Logger or a sort without colliding, because the full name of each includes the namespace it lives in.
noexcept on a function is a promise that it will not throw. If a noexcept function throws anyway, the program calls std::terminate. The specifier is also a compile-time boolean that std::vector uses to decide whether to move or copy on reallocation.
Operators are the built-in symbols that compute, compare, assign, and reach into objects: +, ==, =, [], *, and the rest. Precedence and associativity decide which one runs first when you do not write parentheses.
A pointer is an object that stores the address of another object (or a function). You dereference it with * to reach the thing it points at, and you may reseat it, set it to nullptr, or walk it through an array.
Primitive types are the built-in scalars the compiler already knows: integers, floating-point numbers, bool, and char variants. They occupy a fixed number of bytes and have no constructor or destructor of their own.
Range-for walks a sequence without an index: for (auto& item : items). The compiler calls begin and end, binds the loop variable to each element, and stops when the iterators compare equal.
A reference is another name for an object that already exists. After int& r = n;, r and n are the same object: writes through one are visible through the other, and a reference cannot be reseated.
static_assert(condition, "message") is a compile-time check. If condition is false, the program does not compile and the message is printed. If it is true, the line generates no code.
std::any is a value that can hold a single copy-constructible object of any type, or hold nothing. The type is erased; you recover it with std::any_cast. Prefer std::variant when the set of types is known.
std::optional is a value that may hold a T or hold nothing. It replaces "pointer that might be null" and "sentinel such as -1" when the absence of a result is a normal outcome, not a crash.
std::variant holds exactly one value, whose type is one of the listed alternatives. It is a type-safe union: the active type is tracked, and reading the wrong alternative throws or is a compile-time miss with std::get.
A structured binding unpacks an array, a pair-like type, or a struct into named aliases: auto [key, value] = *it;. The names are bound to the elements; they are not a new tuple.
Specialization gives a template a different implementation for particular template arguments. The generic version stays as the fallback, and the compiler picks the most specific match for the types you actually use.
A template is a pattern for code, not code itself. You write the algorithm or class once with the type left as a parameter, and the compiler generates a separate concrete version for every type you actually use.
A translation unit is a single source file after the preprocessor has pasted in all its headers and expanded its macros. It is the unit the compiler sees, and it sees nothing else in your project.
The using keyword does four unrelated jobs: it imports a whole namespace, imports one specific name, declares a type alias, and inherits a base class's constructors. Only the spelling is shared.
A variadic template accepts any number of template arguments, each with its own type. The group is called a parameter pack, and the compiler expands it into real arguments when the template is instantiated.
A condition variable lets a thread sleep until another thread announces that a condition might be true. In C++ you wait on a std::unique_lock and a predicate; you wake waiters with notify_one or notify_all.
A data race is two threads accessing one memory location at the same time, at least one of them writing, without a happens-before edge between the accesses. In C++ a data race is undefined behaviour: the program may do anything, including appear to work.
A deadlock is a set of threads that will never proceed because each is waiting for a resource another holds. The usual C++ form is two mutexes locked in opposite orders. The process does not crash; it hangs.
Memory order is the constraint you attach to an atomic operation that says how it synchronises with other atomics and with ordinary reads and writes. seq_cst is the default and the safest. acquire/release pair a publish with a consume. relaxed only makes the one access atomic.
std::async runs a function asynchronously and gives you a std::future for the result (or the exception). The launch policy chooses a new thread or a deferred call that runs when you get.
std::atomic is a variable whose reads and writes are indivisible to other threads. A data race on an atomic is not a data race in the standard's sense: the operations are well-defined. Use it for flags, counters, and simple published pointers — not as a replacement for a mutex around a vector.
A std::future is a one-shot handle to a value (or exception) that another thread — or a deferred task — will produce. get() waits, returns the T (or void), and leaves the future empty. A second get throws std::future_error.
std::jthread (C++20) is a thread whose destructor joins. It also carries a std::stop_token so you can ask the worker to stop cooperatively. Prefer it over a raw std::thread whenever the toolchain has C++20.
std::lock_guard locks a mutex in its constructor and unlocks it in its destructor. It is the default RAII wrapper for a critical section that lasts exactly one scope.
std::mutex is a mutual-exclusion lock. Only one thread can own it at a time. You lock it before touching shared data and unlock it after. Lock it with std::lock_guard or std::unique_lock, not with bare lock()/unlock() in application code.
A std::promise is the write end of a shared state. You set_value or set_exception once. A std::future from get_future() is the read end. Together they move one result between threads without a mutex you write yourself.
std::scoped_lock (C++17) locks zero or more mutexes for a scope and unlocks them in the destructor. With two or more mutexes it uses a deadlock-avoiding lock algorithm, so you do not have to pick a manual lock order.
std::thread starts a new OS thread that runs a function you pass to the constructor. You must join or detach it before the std::thread object is destroyed, or std::terminate is called.
std::unique_lock is a movable RAII lock that can unlock and relock. Condition variables require it. Use lock_guard when you only need "lock for this scope"; use unique_lock when you need to drop the lock before the scope ends.
CORS is a browser rule that blocks a web page on one origin from reading a response from another origin unless the server opts in with headers. A C++ API that browsers call must send Access-Control-Allow-Origin (and friends). A C++ client that is not a browser ignores CORS.
HTTP is the request-and-response protocol the web runs on. A C++ program is usually a client (libcurl, cpp-httplib, Boost.Beast) or a server (Beast, Crow, Drogon, httplib). The language has no net/http in the standard library.
An HTTP client sends requests and reads responses. In C++ you choose a library: libcurl for portable power, cpp-httplib for small tools, Boost.Beast for Asio integration. There is no std::http.
JSON is a text format for objects, arrays, strings, numbers, booleans, and null. C++ has no standard JSON type. nlohmann/json is the usual convenience library; RapidJSON and simdjson are the usual speed libraries.
REST is a style of HTTP API: resources have URLs, methods mean GET/PUT/POST/DELETE, and representations are usually JSON. A C++ service implements that with a router plus a JSON library, not with a standard "REST" type.
An HTTP status code is a three-digit integer on the response that classifies the outcome: 2xx success, 3xx redirect, 4xx client error, 5xx server error. C++ clients read it from the library (res->status, CURLINFO_RESPONSE_CODE). Servers set it on the response object.
TLS (the protocol under HTTPS) encrypts a byte stream and authenticates the server with a certificate. C++ programs use OpenSSL, BoringSSL, or a library that wraps them (libcurl, Asio SSL, httplib). You do not implement TLS yourself.
Iterator categories classify what an iterator can do: read, write, go forward, go backward, or jump by n. Algorithms require a minimum category. std::sort needs random access; std::find needs only a single pass forward.
An iterator is an object that points at an element in a sequence and knows how to move to the next one. Containers expose begin and end. Algorithms read and write through iterators so one std::find works on a vector, a list, and a raw array.
C++20 ranges are a layer over iterators: a range is anything with a beginning and an end (or a sentinel). Algorithms take the range in one argument, and views compose lazily (filter | transform) without allocating an intermediate container.
std::array is a fixed-size sequence of N elements of type T. It wraps a C array with iterators, size(), and value semantics, and it stores the elements inline: no heap allocation.
std::deque is a double-ended queue: O(1) push_front, push_back, pop_front, and pop_back, plus random-access operator[]. Elements live in fixed-size chunks, not one contiguous buffer.
std::list is a doubly linked list. Insert and erase at a known iterator are O(1) and do not invalidate other iterators. Indexing is O(n). Prefer std::vector unless you need splice or stable iterators.
std::map is an ordered dictionary: each key appears once, keys stay sorted, and lookup, insert, and erase are O(log n). It is usually a balanced binary tree (red-black on every mainstream library).
std::priority_queue is a max-heap adapter. top() is the largest element according to the comparator. push and pop are O(log n). There is no iterator and no decrease-key.
std::queue is a first-in, first-out adapter. You push at the back, front and pop at the front. It is not a container with iterators; it is a restricted view over an underlying container, by default std::deque.
std::set is an ordered collection of unique values. Insert, erase, and lookup are O(log n). Iteration walks the values from smallest to largest according to the comparator.
std::span is a non-owning view of a contiguous sequence of T: a pointer and a length. It can refer to a vector, an array, a C array, or a counted pointer, without copying the elements.
std::stack is a last-in, first-out adapter. You push and pop at the top. It wraps an underlying container, by default std::deque. Depth-first search and undo lists are stacks.
std::string is an owning, resizable buffer of char. It stores a contiguous sequence, tracks its length, and frees the buffer in its destructor. It is the default type for mutable text you own.
std::string_view is a non-owning view of a contiguous sequence of char: a pointer and a length. It can refer to a std::string, a string literal, or a substring, without copying the characters.
std::unordered_map is a hash table: each key appears once, order is unspecified, and lookup, insert, and erase are average O(1). Worst case is O(n) if hashes collide.
std::unordered_set is a hash table of unique values. Membership tests and inserts are average O(1). There is no key order. Worst case is O(n) under collisions.
A resizable array that keeps its elements in one contiguous block of heap memory. It owns that block, grows it on demand, and frees it in its destructor, which makes it the default container for a sequence of values.
libpqxx is the official-style C++ client for PostgreSQL. It wraps libpq with RAII connections, transactions, and streams. You write SQL; you do not get an ORM.
A prepared statement is SQL with placeholders (?, $1, :name) that you compile once and bind values to later. The database never mixes those values into the SQL text. That is the defence against injection and the way to reuse a plan.
A RAII connection is a C++ object that opens a database handle in its constructor and closes it in its destructor. Statements and transactions get the same treatment. You do not call sqlite3_close on a dozen error paths by hand.
SOCI is a C++ database access library with a stream-like API (sql << "select ...", soci::into(x)). One frontend, several backends: PostgreSQL, SQLite, MySQL, Oracle, ODBC. You write C++ types; the backend talks to the driver.
SQL injection is when untrusted text is copied into a SQL string and parsed as SQL. The attacker changes the statement's meaning. The fix in C++ is the same as everywhere: prepared statements and bound parameters, never sql += user.
SQLite is an embedded relational database: a C library plus a file (or a memory store). Your C++ process links sqlite3 and calls sqlite3_open, sqlite3_prepare_v2, sqlite3_bind_*, sqlite3_step. There is no separate database server.
A transaction is a group of SQL statements that commit together or roll back together. In C++ the transaction should be an object: constructor BEGIN, commit() persists, destructor ROLLBACK if you never committed.