Я имею в виду параметры (4), (5) и (6) std::optional::operator=
Учитывая, что
The class template std::optional manages an optional contained value, i.e. a value that may or may not be present.
(4) по ссылке в описании:
The function does not participate in overload resolution unless std::decay_t (until C++20)std::remove_cvref_t (since C++20) is not std::optional, std::is_constructible_v is true, std::is_assignable_v is true, and at least one of the following is true:
T is not a scalar type;
std::decay_t is not T.
Похоже, что из приведенного выше следует, что U не является std::optional, но поскольку std::optional может быть T, как это условие соотносится с другим условием
std::is_constructible_v is true, std::is_assignable_v is true
Кроме того, если T не является скалярным типом, как может работать присвоение, если std::decay_t не является T?
(5) и (6) состояния
These overloads do not participate in overload resolution unless the following conditions are met:
T is not constructible, convertible, or assignable from any expression of type (possibly const) std::optional, i.e., the following 12 type traits are all false:
std::is_constructible_v
std::is_constructible_v
std::is_constructible_v
std::is_constructible_v
std::is_convertible_v
std::is_convertible_v
std::is_convertible_v
std::is_convertible_v
std::is_assignable_v
std::is_assignable_v
std::is_assignable_v
std::is_assignable_v.
Опять же, std::optional может быть U, и если да, то как происходит присвоение?
Далее в описании говорится:
For overload (5), std::is_constructible_v and std::is_assignable_v are both true.
For overload (6), std::is_constructible_v and std::is_assignable_v are both true
Разве это не было бы так, если бы std::optional содержал U?
Должно ли считать, что std::optional и std::optional не имеют допустимых значений для разрешения вышеуказанных очевидных противоречий?
На основании приведенного ниже тестового кода, std::optional и T — разные типы.
#include
#include
#include
#include
#include
using std::optional;
using std::is_same;
using std::string;
using std::boolalpha;
using std::cout;
using std::endl;
int main (){
optional opt("yes");
string s("yeah");
cout
Подробнее здесь: https://stackoverflow.com/questions/771 ... -operators