viboes / std-make

C++ generic make factory

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

P0196: none and Nullable types - The section on nesting is unclear

tituswinters opened this issue · comments

The section on nesting is unclear.

One of the benefits of the original notion of having none_t was that it could be used where necessary to disambiguate cases like:
optional<any> oa = none;
via
optional<any> oa = none_t<any>{};
vs.
optional<any> oa = {};

I believe that we don't need to support this case as any is already Nullable.

IMO this is equivalent to nesting smart pointers

 unique_ptr<unique_ptr<int>> uui = nullptr;

Is the intent to demonstrate that there is no need to do anything special for any nested nullable types?

Yes and not.

I wanted to reduce the scope of the proposal and provide the same kind of interface for Nullable than for as NullablePointer (none versus nullptr).

The paper includes an alternative design with lift that could respond to the need.

 optional<any> oa = lift(none);

This works when there is enough context (no ambiguity) and the optional class adds a conversion from lifted<U>. Does this respond to your needs or do you need the general case to disambiguate?

If you need the general case for Nullable, you would need it also for NullablePointer types, isn't it?
I plan to provide the case explicit case for Nullable and NullablePointer types with a function no_value, but this will be part of the C++ generic factories paper. no_value would be a function because it accepts class templates (optional) and classes (any).

optional<int> oan = no_value<optional>(); //
any an = no_value<any>(); 
unique_ptr<any> upn = no_value<unique_ptr>(); 

optional<any> oav = no_value<any>(); 
unique_ptr<optional<int>> oav = no_value<optional>(); 
unique_ptr<any> oav = no_value<any>(); 

This requires however some specific conversion from the result of no_value() to optional, any, unique_ptr, ...

I think the "lift" design (placed where it is in the paper) is confusing. Perhaps if you shift it to the end of the paper as an appendix "Alternate designs" that might help.

Agreed. I planed to do it.

lift was removed.