如何取消初始化std :: experimental :: optional

时间:2016-04-26 14:01:38

标签: c++

如何取消初始化std :: experimental :: optional?

  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;
  }

如何点击其他分支?

1 个答案:

答案 0 :(得分:3)

name = std::experimental::nullopt; 

link

  

std :: experimental :: nullopt是std :: experimental :: nullopt_t类型的常量,用于表示具有未初始化状态的可选类型。