Results for “Errors & optional values”
Small, practical examples. Search by task or narrow things down below.
Observe shared ownership without extending its lifetime
C++: A weak_ptr can be locked while an owner exists and becomes expired after the last owner is released.
C++✓ Tested
Own one dynamically allocated value with unique_ptr
C++: make_unique allocates a value whose lifetime is tied to its owning smart pointer.
C++✓ Tested
Read a variant only when it holds the expected type
C++: get_if returns a null pointer rather than throwing for another active alternative.
C++✓ Tested
Run cleanup through a scoped destructor
C++: A stack object’s destructor runs when its scope exits, including normal exception unwinding.
C++✓ Tested
Share ownership with a counted smart pointer
C++: Copies of shared_ptr keep the owned value alive until the last owner is released.
C++✓ Tested
Store a reference in a standard container
C++: reference_wrapper preserves reference semantics while behaving like a copyable container element.
C++✓ Tested
Transfer unique ownership with move
C++: Moving a unique_ptr leaves the source empty and gives ownership to the destination.
C++✓ Tested
Test missing values with IS NULL
Find rows where an optional value is absent.
IS NULL✓ Tested
Add an optional field to an existing table
SQL: A nullable column permits existing rows to remain valid while data is filled later.
SQL✓ Tested
Add an optional field to an existing table
SQL Server: A nullable column permits existing rows to remain valid while data is filled later.
SQL Server✓ Tested
Add an optional field to an existing table
Postgres: A nullable column permits existing rows to remain valid while data is filled later.
Postgres✓ Tested
Add an optional field to an existing table
SQLite: A nullable column permits existing rows to remain valid while data is filled later.
SQLite✓ Tested