Skip to content

Commit

Permalink
STYLE: Use DoubleToStringConverter::ToShortestString overload set
Browse files Browse the repository at this point in the history
Simplified ITK's `FloatingPointNumberToString` implementation by using `DoubleToStringConverter::ToShortestString` overload set, proposed by pull request google/double-conversion#159

Related to issue google/double-conversion#160 "Add generic (template) methods for to_string (float or double)", opened by Florian Loitsch (floitsch).
  • Loading branch information
N-Dekker committed Apr 13, 2021
1 parent 4ce3383 commit 3098b88
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions Modules/Core/Common/src/itkNumberToString.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@
namespace
{

bool
ConvertToShortest(const double_conversion::DoubleToStringConverter & converter,
const double val,
double_conversion::StringBuilder & builder)
{
return converter.ToShortest(val, &builder);
}

bool
ConvertToShortest(const double_conversion::DoubleToStringConverter & converter,
const float val,
double_conversion::StringBuilder & builder)
{
// Call the converter member function that is specific for single-precision `float`.
return converter.ToShortestSingle(val, &builder);
}

template <typename TValue>
std::string
FloatingPointNumberToString(const TValue val)
Expand All @@ -52,7 +35,7 @@ FloatingPointNumberToString(const TValue val)

double_conversion::StringBuilder builder(buf, sizeof(buf));

if (!ConvertToShortest(double_conversion::DoubleToStringConverter::EcmaScriptConverter(), val, builder))
if (!double_conversion::DoubleToStringConverter::EcmaScriptConverter().ToShortestString(val, &builder))
{
itkGenericExceptionMacro(<< "Conversion failed for " << val);
}
Expand Down

0 comments on commit 3098b88

Please sign in to comment.