Tencent/flare

Why use std::common_type in TryParseTraits

npuichigo opened this issue · 2 comments

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...);
  }
};

So as not to instantiate T, whose default constructor (if there’s one at all) might be non-trivial or have side effect.

Thanks for your quick reply