Skip to content

Commit

Permalink
nomerge: guessing what msvc could complain about
Browse files Browse the repository at this point in the history
  • Loading branch information
SGSSGene committed Jul 30, 2024
1 parent acf2e70 commit f40095f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
10 changes: 7 additions & 3 deletions include/yaml-cpp/fptostring.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@

namespace YAML {
// "precision = 0" refers to shortest known unique representation of the value
YAML_CPP_API std::string FpToString(float v, size_t precision = 0);
YAML_CPP_API std::string FpToString(double v, size_t precision = 0);
YAML_CPP_API std::string FpToString(long double v, size_t precision = 0);
YAML_CPP_API std::string FpToString(float v, size_t precision );
YAML_CPP_API std::string FpToString(double v, size_t precision);
YAML_CPP_API std::string FpToString(long double v, size_t precision);
YAML_CPP_API std::string FpToString(float v);
YAML_CPP_API std::string FpToString(double v);
YAML_CPP_API std::string FpToString(long double v);

}

#endif
10 changes: 10 additions & 0 deletions src/fptostring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,14 @@ std::string FpToString(long double v, size_t precision) {
return ss.str();
}

std::string FpToString(float v) {
return FpToString(v, 0);
}
std::string FpToString(double v) {
return FpToString(v, 0);
}
std::string FpToString(long double v) {
return FpToString(v, 0);
}

}
7 changes: 4 additions & 3 deletions test/fptostring_test.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "yaml-cpp/fptostring.h"
#include "gtest/gtest.h"

namespace YAML {

using YAML::FpToString;

namespace {

/**
* Helper function, that converts double to string as std::stringstream would do
*/
template <typename T>
static std::string convert_with_stringstream(T v, size_t precision = 0) {
std::string convert_with_stringstream(T v, size_t precision = 0) {
std::stringstream ss;
if (precision > 0) {
ss << std::setprecision(precision);
Expand Down Expand Up @@ -239,4 +241,3 @@ TEST(FpToStringTest, conversion_float) {
}

} // namespace
} // namespace YAML

0 comments on commit f40095f

Please sign in to comment.