std::move_constructible(3)

πŸ“¦
version 2024.07.05 Β· 3 versions
, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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 type T, and
  • u2, a distinct object of type T equal to rv,

the following are true:

  • After the definition T u = rv;, u is equal to u2;
  • T(rv) is equal to u2; and
  • If T is not const-qualified, then rv'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 template
  • is_trivially_move_constructible β€” checks if a type can be constructed from an rvalue (C++11) β€” class template
  • is_nothrow_move_constructible (C++11) β€” class template
  • and a reference for 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