Return type std::optional>

前端 未结 2 1076
盖世英雄少女心
盖世英雄少女心 2021-02-19 21:04

I have a situation where a function must return a value taken from a table. A cell in this table (let\'s assume the table just works...) may contain a value, or it might not. T

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 21:14

    Just want to add that before C++17 and the standardization of variant and monostate, there is already boost::blank to solve the exact same issue for boost::variant.

    By convention, if boost::blank is used, it should always be the first template argument, so that a default-constructed variant is empty and checking for emptyness is done with .which() == 0.

提交回复
热议问题