Here, I keep a note list of C++ features that I find interesting or useful. Beware that I've written those notes down on the fly as I understood them and my understanding might be incomplete or incorrect!
Source:
A list (to have them in one place), source/inspiration:
noreturn
, deprecated("description")
, fallthrough
, (un)likely
,
maybe_unused
(be careful)
carries_dependency
release/acquire
dependency passingkill_dependency
to undonodiscard
no_unique_address
msvc::no_unique_address
for MSVCassume(predicate expr)
std::boolalpha
- to print true
/false
instead of 1
/0
The initial parts are particularly useful if you'd like to refresh on the parameter pack syntax and folds.
Multilambdas are (I think) also explained in Jason Turner's C++ weekly series, as well as fold expressions.
From their about page:
C++ Insights is a clang-based tool which does a source to source transformation. Its goal is to make things visible, which normally and intentionally happen behind the scenes. It's about the magic the compiler does for us to make things work. Or looking through the classes of a compiler.
this
class C {
void f(this C& self) {}
// deducing this
template <class C>
auto&& g(this C&& self) {}
}
if consteval
if consteval { A } else { B }
()
and before ()
- behind []
- for attribute on the call - e.g. [[nodiscard]]
)uz
and UZ
literals for std::size_t
auto(x)
and auto{x}
to get prvalue
swarning
, elifdef
and elifndef
preprocessor directivesstd::unreachable
- invoking this at runtime invokes UB (optimizations)[[assume(expr)]]
syntax for assumptionsU'\N{GREEK CAPITAL LETTER DELTA}'
std::optional
transform
, and_then
, or_else
starts_with
, ends_with
shift_left
, shift_right
, find_last(_if/_if_not)
=> subrange or {last, last}
cotnains
(element), contains_subrange
to
- ranges to containersauto set{ std::ranges::to<std::set>(vectorData) };
auto set { vectorData | std::ranges::to<std::set<double>() };
auto set {std::from_range, vectorData}
fold_left
, fold_right
fold_left_first
, fold_right_last
fold_left_with_iter, fold_left_first_with_iter
zip
and zip_transform
adjacent<WINDOW_SIZE>
and adjacent_transform
pairwise
and pairwise_transform
as adjacent<2>
slide
- like adjacent
but with a runtime window sizechunk
- like slide but the window is not sliding, but jumping
chunk_by
- with a predicate where to make the cutjoin_with
!!!stride(n)
skips elementsrepeat
- bounded or unboundedcartesian_product
as_rvalue
- std::move
, the viewstd::expected
has_value
, value
(throws), error
, error_value
std::optional
std::print
, println
- it's even faster!
format
) for ranges
{}, {::}, {:n}, {:n:n:*^4}
import std;
flat_map
, ... - adapters over containers
mdspan
- layout policy -> N-dimensional coordinates -> 1D indexgenerator
- coroutine-based
string::conatins
!!!string::resize_and_overwrite(count, op)
- resize and initialize potential new elements with op(data, neededCount)
<stacktrace>
!!!std::move_only_function<F>
spanstream
- stream operations on external buffers
ispanstream
, ospanstream
byteswap
!!!to_underlying
-> enum
to underlying_type_t
[i = 1]() mutable { i += 2; return i; }
- mutable lambda with state (state is reused accross calls)
3rd June 2024