I was just reading through Bartek's blog when I found this example:
auto to_int( char const * const text ) -> std::optional<int>
{
char * pos = nullptr;
const int value = std::strtol( text, &pos, 0 );
return pos == text ? std::nullopt : std::optional<int>( value );
}
Why did they use the idiom auto to_int( char const * const text ) -> std::optional<int>?
Isn't this the same as the traditional std::optional<int> to_int( char const * const text )?
Is there a reason to prefer one or the other in certain situations? If so, what would these situations be?
NOT DUPLICATE
This question is not the same as the one Vittorio Romeo presented as justification for closing it. I'm not asking for an opinion. I'm asking technically why this idiom was used - it is a valid question.
User Vittorio Romeo DO NOT CLOSE QUESTIONS WITHOUT READING THEM FIRST. This is completely unrelated to the question you pointed to as duplicate. This is a technical question. Not asking for opinion at all and I'm not asking if this should become the norm either.
Aucun commentaire:
Enregistrer un commentaire