std::copy_constructible(3)

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

πŸ’– NAME πŸ’–

std::copy_constructible β€” std::copy_constructible, bestie. That's the whole name, no notes. This is the std::copy_constructible(3) page from the C++ Standard Libary manual β€” yes, β€œLibary,” and we love a chaotic spelling moment πŸ’…

πŸ¦‹ Synopsis πŸ¦‹

Defined in header <concepts>.

(since C++20)

template< class T >

concept copy_constructible =
    std::move_constructible<T> &&
    std::constructible_from<T, T&> && std::convertible_to<T&, T> &&
    std::constructible_from<T, const T&> && std::convertible_to<const
T&, T> &&

    std::constructible_from<T, const T> && std::convertible_to<const
T, T>;

Okay so the vibe check: copy_constructible is satisfied if T is an lvalue reference type, or if it is a move_constructible object type where an object of that type can be constructed from a (possibly const) lvalue or const rvalue of that type in both direct- and copy-initialization contexts with the usual semantics (a copy is constructed with the source unchanged). No cap, the source stays untouched 🫢

🧠 Semantic requirements 🧠

If T is an object type, then copy_constructible<T> is modeled only if given

  • v, an lvalue of type (possibly const) T or an rvalue of type const T,

the following are true:

  • After the definition T u = v;, u is equal to v and v is not modified;
  • T(v) is equal to v and does not modify v.

πŸ” See also πŸ”

The see-also crew β€” all (C++11), all (class template), and the page’s description is checks if a type has a copy constructor:

  • is_copy_constructible β€” (C++11), (class template)
  • is_trivially_copy_constructible β€” (C++11), (class template)
  • is_nothrow_copy_constructible β€” (C++11), (class template)

Sign-off, because we keep it cute: source http://cppreference.com, version/date 2024.06.10, page std::copy_constructible(3). Go off and copy-construct responsibly, bestie πŸ’–βœ¨

πŸ“¦ where this page comes from