summaryrefslogtreecommitdiff
path: root/src/raw_convert.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-12-26 01:41:11 +0100
committerCarl Hetherington <cth@carlh.net>2024-12-26 01:41:11 +0100
commit2fe5f14f26904eed37c5c82dad5210de7254cf63 (patch)
tree2de319d2f55a4e2d7683a80d47cde71b0496a90f /src/raw_convert.h
parent7e1c9751475b5ce8f03e52ba3f031c68f0c511af (diff)
Use fast_format for raw_convert to int/double.
Diffstat (limited to 'src/raw_convert.h')
-rw-r--r--src/raw_convert.h72
1 files changed, 8 insertions, 64 deletions
diff --git a/src/raw_convert.h b/src/raw_convert.h
index 8dde240d..98eff4e0 100644
--- a/src/raw_convert.h
+++ b/src/raw_convert.h
@@ -42,80 +42,24 @@
#include "util.h"
-#include <boost/static_assert.hpp>
-#include <iomanip>
+#include <fast_float/fast_float.h>
namespace dcp {
-/** A sort-of version of boost::lexical_cast that does uses the "C"
- * locale (i.e. no thousands separators and a . for the decimal separator).
+/** Wrapper for fast_float::from_chars, which converts strings to numbers using
+ * the "C" locale (i.e. no thousands separators, . is the decimal separator).
*/
-template <typename P, typename Q>
+template <typename P>
P
-raw_convert (Q, int precision = 16, bool fixed = false)
+raw_convert(std::string v)
{
- /* We can't write a generic version of raw_convert; all required
- versions must be specialised.
- */
- BOOST_STATIC_ASSERT (sizeof (Q) == 0);
- LIBDCP_UNUSED(precision);
- LIBDCP_UNUSED(fixed);
+ P result = 0;
+ fast_float::from_chars(v.data(), v.data() + v.size(), result);
+ return result;
}
-template <>
-unsigned char
-raw_convert (std::string v, int, bool);
-
-template <>
-unsigned short int
-raw_convert (std::string v, int, bool);
-
-template <>
-int
-raw_convert (std::string v, int, bool);
-
-template <>
-long
-raw_convert (std::string v, int, bool);
-
-template <>
-unsigned long
-raw_convert (std::string v, int, bool);
-
-template <>
-long long
-raw_convert (std::string v, int, bool);
-
-template <>
-unsigned long long
-raw_convert (std::string v, int, bool);
-
-template <>
-int
-raw_convert (char* v, int, bool);
-
-template <>
-int
-raw_convert (char const * v, int, bool);
-
-template <>
-float
-raw_convert (std::string v, int, bool);
-
-template <>
-float
-raw_convert (char const * v, int, bool);
-
-template <>
-double
-raw_convert (std::string v, int, bool);
-
-template <>
-double
-raw_convert (char const * v, int, bool);
-
}