
Yuval Ronen wrote:
Fernando Cacciola wrote:
So my current proposal would be:
Remove direct-assignment. Let copy-assigment be the only way to define the wrapped value Add make_optional() and make_optional_ref() as shorcuts to help with copy-assignment Keep none-assignment as the only wat to clear the wrapped value.
Does this mean that construction from T is also suggested to be removed? I assume not...
You assume correct.
Anyway, If I'm required to write
optional<T> o = x; ... o = optional<T>(y);
or
optional<T> o = x; ... o = make_optional(y);
then it should be considered that this generates an additional temporary instance of y (of type T). Direct assignment from T doesn't suffer from this.
Good point. Still, I'm not sure this is significant enough to go back to direct assigment though. Specially given that this is precisely the situation rvalue references are for (and I think we can safely bet they will be part of C++ even before optional<>).
Working around this makes me write
optional<T>(y).swap(o);
or
make_optional(y).swap(o);
which is completely different...
Ya, that's reasonable alternative. I wouldn't worry too much about it though, chances are C++ will soon overcome clearly unnecesary temporaties like that without such code gymnastics. -- Fernando Cacciola SciSoft http://fcacciola.50webs.com/