Почему std::expected требует, чтобы T был допускающим копирование, если он допускает копирование?C++

Программы на C++. Форум разработчиков
Anonymous
Почему std::expected требует, чтобы T был допускающим копирование, если он допускает копирование?

Сообщение Anonymous »


If we have a type T that is not copy-constructible but copy-assignable:

struct T { T() = default; ~T() = default; T(const T&) = delete; T(T&&) = default; T& operator=(const T&) = default; T& operator=(T&&) = default; }; then std::is_copy_assignable_v is obviously true, but std::is_copy_assignable_v is false.

This behavior is described on cppreference: std::expected::operator=

What is the rationale behind this? Why couldn't we allow std::expected to be copy-assignable if T is copy-assignable, even if it is not copy-constructible? The same question also applies to move assignability.


Источник: https://stackoverflow.com/questions/780 ... is-copy-as

Вернуться в «C++»