The return type is std :: optional <std :: variant <... >>

I have a situation where a function should return a value taken from a table. A cell in this table (let's say the table just works ...) may or may not contain a value. This value can also be one of several types: int, double, string, date(but of a different type).

What would return such a function? Is it a good idea to come back std::optional<std::variant<std::string, int, double, std::chrono::time_point>>?

Is it good to use optionaland variant?

+6
source share
1 answer

, std::monostate. , variant<std::monostate, int, double, std::string, std::chrono::time_point>. monostate , a variant .

, optional<variant> , . , monostate, visit "" .

+11

Source: https://habr.com/ru/post/1017357/


All Articles