do not implicitly to_string as a fallback in format
This commit is contained in:
parent
5a76f29dea
commit
3aa5db5b1c
|
@ -173,17 +173,6 @@ namespace detail {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fallback test for whether a value can be converted to string */
|
|
||||||
template<typename T>
|
|
||||||
static std::true_type test_fmt_tostr(
|
|
||||||
decltype(ostd::to_string<T>{}(std::declval<T>())) *
|
|
||||||
);
|
|
||||||
template<typename>
|
|
||||||
static std::false_type test_fmt_tostr(...);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr bool fmt_tostr_test = decltype(test_fmt_tostr<T>(0))::value;
|
|
||||||
|
|
||||||
/* ugly ass check for whether a type is tuple-like, like tuple itself,
|
/* ugly ass check for whether a type is tuple-like, like tuple itself,
|
||||||
* pair, array, possibly other types added later or overridden...
|
* pair, array, possibly other types added later or overridden...
|
||||||
*/
|
*/
|
||||||
|
@ -734,14 +723,6 @@ private:
|
||||||
write_float(writer, val);
|
write_float(writer, val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* stuff that can be to_string'd, worst reliable case, allocates */
|
|
||||||
if constexpr(detail::fmt_tostr_test<T>) {
|
|
||||||
if (spec() != 's') {
|
|
||||||
throw format_error{"custom objects need the '%s' spec"};
|
|
||||||
}
|
|
||||||
write_val(writer, false, ostd::to_string<T>{}(val));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* we ran out of options, failure */
|
/* we ran out of options, failure */
|
||||||
throw format_error{"the value cannot be formatted"};
|
throw format_error{"the value cannot be formatted"};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue