mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 15:09:19 +02:00
Do not allow implicit cast for inline std::string to_string(bool Value) and change to_string to std::string for non boolean values
This commit is contained in:
@@ -212,7 +212,7 @@ std::string to_minutes_str(float const Minutes, bool const Leadingzero, int cons
|
||||
float minutesintegral;
|
||||
auto const minutesfractional{std::modf(Minutes, &minutesintegral)};
|
||||
auto const width{Width - 1};
|
||||
auto minutes = (std::string(width - 1, ' ') + (Leadingzero ? to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0)));
|
||||
auto minutes = (std::string(width - 1, ' ') + (Leadingzero ? std::to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0)));
|
||||
return (minutes.substr(minutes.size() - width, width) + fractionlabels[static_cast<int>(std::floor(minutesfractional * 10 + 0.1))]);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,8 @@ std::string to_string(double Value, int precision, int width);
|
||||
std::string to_hex_str(int const Value, int const width = 4);
|
||||
std::string to_minutes_str(float const Minutes, bool const Leadingzero, int const Width);
|
||||
|
||||
inline std::string to_string(bool Value)
|
||||
template <std::same_as<bool> T> // Without this line this function can be used with other types implicit casted to boolean which may create hard to debug bugs.
|
||||
inline std::string to_string(T Value)
|
||||
{
|
||||
return (Value == true ? "true" : "false");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user