std::move_constructible(3)
π std::move_constructible β a whole mood (C++ Standard Libary, section 3)
okay so bestie, buckle up π this one is from the C++ Standard Libary manual, section 3, and it's genuinely one of those concepts that sounds scary but is actually just "can you move this thing into a new home, yes or no" π
β¨ NAME β¨
std::move_constructible β literally that. std::move_constructible. iconic, no notes π
πΈ SYNOPSIS πΈ
Defined in header <concepts>, and it goes a little something like this:
template< class T >
concept move_constructible = std::constructible_from<T, T> &&
std::convertible_to<T, T>;
and this whole thing has been a thing since C++20 β
So here's the vibe check π¦: the concept move_constructible is satisfied if T is a reference type, or if it's an object type where an object of that type can be constructed from an rvalue of that type β and it has to work in both direct-initialization and copy-initialization contexts, with the usual semantics. both. not one. both. π
π Semantic requirements π
If T is an object type, then move_constructible<T> is modeled only if β and this is the important part, don't skip it π β given:
rv, an rvalue of typeT, andu2, a distinct object of typeTequal torv,
the following are true:
- After the definition
T u = rv;,uis equal tou2; T(rv)is equal tou2; and- If
Tis not const-qualified, thenrv's resulting state (after the definition/expression is evaluated in either bullets above) is valid but unspecified; otherwise, it is unchanged.
ngl that last bullet is the one that gets people π "valid but unspecified" is not a free pass to do crimes, it's a very specific kind of "we're not telling you what's in there, but it's legal" situation. respect the unspecified state. π«Ά
π See also π
is_move_constructible(C++11) β class templateis_trivially_move_constructibleβ checks if a type can be constructed from an rvalue (C++11) β class templateis_nothrow_move_constructible(C++11) β class template- and a
referencefor you too, bestie (C++11) β¨
that's the whole page, we ate and left no crumbs π π₯
http://cppreference.com Β· 2024.06.10 Β· std::move_constructible(3) β mwah, go move-construct something responsibly π§ββοΈπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms