FIND YOUR NEXT FEW LINES

Results for “optional”

Small, practical examples. Search by task or narrow things down below.

48 snippets foundClear filters
JavaScriptObjects & JSON

Read a nested value safely

Combine optional chaining with nullish coalescing in JavaScript.

JavaScript✓ Tested
C++Ownership & optional values

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
C++Ownership & optional values

Run cleanup through a scoped destructor

C++: A stack object’s destructor runs when its scope exits, including normal exception unwinding.

C++✓ Tested
C++Ownership & optional values

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
RustErrors & optional values

Stop collecting when parsing fails

Stop collecting when parsing fails in a complete Rust program using the standard library.

Rust✓ Tested
C++Ownership & optional values

Store a reference in a standard container

C++: reference_wrapper preserves reference semantics while behaving like a copyable container element.

C++✓ Tested
C++Ownership & optional values

Transfer unique ownership with move

C++: Moving a unique_ptr leaves the source empty and gives ownership to the destination.

C++✓ Tested
PythonFunctions & error handling

Avoid a shared mutable default argument

Python: Create a fresh list inside the function when the optional argument is omitted.

Python✓ Tested
HTMLData & disclosure

Create a native disclosure

Use details and summary to show optional HTML content without JavaScript.

HTML✓ Tested
Docker / ComposeCompose service options

Drop capabilities for a Compose service

Docker / Compose: cap_drop ALL removes optional Linux capabilities.

Docker / Compose✓ Tested
SQL ServerDates & text

Find the final day of a month

Use EOMONTH without manually calculating month length.

EOMONTH✓ Tested
SQLChange & combine data

Test missing values with IS NULL

Find rows where an optional value is absent.

IS NULL✓ Tested