2016-04-26 30 views
2

如何uninitialize std :: experimental :: optional?如何uninitialize std :: experimental ::可選

std::experimental::optional<std::string> name; 

    name = std::string("hello"); //how to uninitialize name? 

    if(name) 
    { 
    std::cout << "name is set" << std::endl; 
    } 
    else 
    { 
    std::cout << "name is not set" << std::endl; 
    } 

我該如何擊中else分支?

+1

我很難理解你想要什麼。你是否想要執行if和else塊,或者你想「空」出'name',所以只有else塊運行? – NathanOliver

+0

我想取消初始化名稱。 – user3828398

回答

3
name = std::experimental::nullopt; 

link

的std ::實驗:: nullopt是類型爲std ::實驗:: nullopt_t是,用於指示可選類型與未初始化狀態的一個常數。

相關問題