Skip to main content
9 events
when toggle format what by license comment
Oct 9, 2021 at 17:10 vote accept jdt
Oct 9, 2021 at 16:43 comment added G. Sliepen It could be useful in some situations, but this quickly gets ugly. Consider that if you call std::string s{"Hello"}; printName(s);, that even though you pass the std::optional via reference, it is actually going to construct a temporary std::optional that holds a copy of the string s.
Oct 9, 2021 at 16:26 comment added jdt Do you think it could be a good idea to use std::optional for function arguments with something like this: void printName(const std::optional<std::string>& name = std::nullopt)?
Oct 9, 2021 at 9:48 comment added Toby Speight I don't think that std::from_chars() is suitable - see my comment on JDługosz's answer.
Oct 9, 2021 at 7:12 comment added G. Sliepen @JDługosz How? You need to check the return value from std::from_chars(), same as for std::stoi().
Oct 8, 2021 at 22:48 comment added JDługosz Using the newer from_chars prevents the need to check whether it took the whole input.
Oct 8, 2021 at 7:50 comment added Toby Speight Two schools of thought on the correct stream for the failure message. The other view is that if we're prompting, then we should use the same stream as the prompt.
Oct 8, 2021 at 6:27 history edited G. Sliepen CC BY-SA 4.0
deleted 4 characters in body
Oct 7, 2021 at 20:41 history answered G. Sliepen CC BY-SA 4.0