Why is std::nullopt_t part of the C++ standard?

前端 未结 2 689
一生所求
一生所求 2021-01-13 18:14

I don\'t understand the reasoning for the inclusion of std::nullopt_t in the standard. Does it exist strictly for convenience, or is it required in some niche c

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 18:47

    nullopt_t is the type of nullopt which indicates disengaged optional state. nullopt allows disambiguating overloads such as (example from the optional proposal):

    void run(complex v);
    void run(optional v);
    
    run(nullopt);              // pick the second overload
    run({});                   // ambiguous
    

提交回复
热议问题