File indexing completed on 2025-07-05 08:37:53
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_MATH_TOOLS_CONVERT_FROM_STRING_INCLUDED
0008 #define BOOST_MATH_TOOLS_CONVERT_FROM_STRING_INCLUDED
0009
0010 #ifdef _MSC_VER
0011 #pragma once
0012 #endif
0013
0014 #include <boost/math/tools/config.hpp>
0015 #include <type_traits>
0016 #ifndef BOOST_MATH_STANDALONE
0017
0018 #if defined(_MSC_VER) || defined(__GNUC__)
0019 # pragma push_macro( "I" )
0020 # undef I
0021 #endif
0022
0023 #include <boost/lexical_cast.hpp>
0024
0025 #if defined(_MSC_VER) || defined(__GNUC__)
0026 # pragma pop_macro( "I" )
0027 #endif
0028
0029 #endif
0030
0031 namespace boost{ namespace math{ namespace tools{
0032
0033 template <class T>
0034 struct convert_from_string_result
0035 {
0036 typedef typename std::conditional<std::is_constructible<T, const char*>::value, const char*, T>::type type;
0037 };
0038
0039 template <class Real>
0040 Real convert_from_string(const char* p, const std::false_type&)
0041 {
0042 #ifdef BOOST_MATH_NO_LEXICAL_CAST
0043
0044
0045 static_assert(sizeof(Real) == 0, "boost.lexical_cast is not supported in standalone mode.");
0046 (void)p;
0047 return Real(0);
0048
0049 #elif defined(BOOST_MATH_USE_CHARCONV_FOR_CONVERSION)
0050
0051 if constexpr (std::is_arithmetic_v<Real>)
0052 {
0053 Real v {};
0054 std::from_chars(p, p + std::strlen(p), v);
0055
0056 return v;
0057 }
0058 else
0059 {
0060 return boost::lexical_cast<Real>(p);
0061 }
0062
0063 #else
0064
0065 return boost::lexical_cast<Real>(p);
0066
0067 #endif
0068 }
0069 template <class Real>
0070 constexpr const char* convert_from_string(const char* p, const std::true_type&) noexcept
0071 {
0072 return p;
0073 }
0074 template <class Real>
0075 constexpr typename convert_from_string_result<Real>::type convert_from_string(const char* p) noexcept((std::is_constructible<Real, const char*>::value))
0076 {
0077 return convert_from_string<Real>(p, std::is_constructible<Real, const char*>());
0078 }
0079
0080 }
0081 }
0082 }
0083
0084 #endif
0085