Why use std::common_type in TryParseTraits
npuichigo opened this issue · 2 comments
npuichigo commented
Could anyone help to explain why std::common_type
is need here instead of just using T()
?
template <class T, class>
struct TryParseTraits {
// The default implementation delegates calls to `TryParse` found by ADL.
template <class... Args>
static std::optional<T> TryParse(std::string_view s, const Args&... args) {
return TryParse(std::common_type<T>(), s, args...);
}
};
0x804d8000 commented
So as not to instantiate T
, whose default constructor (if there’s one at all) might be non-trivial or have side effect.
npuichigo commented
Thanks for your quick reply