Debug-output serialization has grown four toText overloads and three bugs: bool prints as 1, strings get quoted only on Tuesdays... and every fix lands in four places. Since C++17 this is one template with if constexpr — fold all the cases into a single function that cannot drift apart.
Implement toText(value) — one function template that converts a value to text, branching on the type at compile time with if constexpr: bool → "true"/"false", integers → decimal digits, std::string → unchanged, floating point → std::to_string. No overload set.
if constexpr + type traits (std::is_same_v, std::is_integral_v, …)bool must produce "true"/"false" (not "1"/"0") — mind the check orderstd::string input is returned unchangedif constexpr branches during instantiation?bool check come before the integral check?if — and why would it fail to compile?Chain: if constexpr (std::is_same_v<T, bool>) … else if constexpr (std::is_same_v<T, std::string>) … else if constexpr (std::is_integral_v<T>) … else ….
A plain runtime if would force every branch to compile for every T — return value; does not compile when T is int. That is exactly what if constexpr avoids.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.