Reputation: 2932
Is there a combination of stod and stoi? So that I could have a string s = "0.1 1 2.3 3 4.4" and stod_stoi_combined(s) would extract me doubles and ints depending on what the input is?
Upvotes: 0
Views: 189
Reputation: 238351
There is no such combination in the standard library.
There can be no such combination, because the return type of a function cannot depend on the value of the parameter. The return type is always the same, not sometimes int and other times double.
You could possibly write a function that returns std::variant<int, double>
. Note that std::variant
isn't part of the standard library until the upcoming C++17, so if you cannot wait, you'll have to use a third party alternative.
Upvotes: 2