Concept Subspace :: sus :: mem :: Copy

template <class T>
concept Copy
requires
std::is_copy_constructible_v<
                   std::remove_const_t<std::remove_reference_t<T>>>
std::is_copy_assignable_v<
                    std::remove_const_t<std::remove_reference_t<T>>> ||
                !std::is_move_assignable_v<
                    std::remove_const_t<std::remove_reference_t<T>>>

A Copy type can be copied to construct a new object and can be assigned to by copy.

Satisfying Copy also implies that the type satisfies Clone.

This concept tests the object type of T, not a reference type T& or const T&.

Typically types should only be Copy when performing a copy is very cheap, and thus unlikely to cause performance problems. For types that are larger or more complex to copy, it is better to make them satisfy Clone instead so that copies are always explicit.

Types that can not be assigned to at all, by copy or move, can still satisfy Copy by being able to construct by copy. This is required for types with const fields.

Example

struct S {
  S() = default;
  S(const S&) = default;
  S& operator=(const S&) = default;
};
static_assert(sus::mem::Copy<S>);
static_assert(sus::mem::Clone<S>);