Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:40

0001 //  Copyright John Maddock 2016.
0002 //  Copyright Matt Borland 2023.
0003 //  Use, modification and distribution are subject to the
0004 //  Boost Software License, Version 1.0. (See accompanying file
0005 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
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 #include <boost/lexical_cast.hpp>
0018 #endif
0019 
0020 namespace boost{ namespace math{ namespace tools{
0021 
0022    template <class T>
0023    struct convert_from_string_result
0024    {
0025       typedef typename std::conditional<std::is_constructible<T, const char*>::value, const char*, T>::type type;
0026    };
0027 
0028    template <class Real>
0029    Real convert_from_string(const char* p, const std::false_type&)
0030    {
0031       #ifdef BOOST_MATH_NO_LEXICAL_CAST
0032 
0033       // This function should not compile, we don't have the necessary functionality to support it:
0034       static_assert(sizeof(Real) == 0, "boost.lexical_cast is not supported in standalone mode.");
0035       (void)p; // Suppresses -Wunused-parameter
0036       return Real(0);
0037 
0038       #elif defined(BOOST_MATH_USE_CHARCONV_FOR_CONVERSION)
0039 
0040       if constexpr (std::is_arithmetic_v<Real>)
0041       {
0042          Real v {};
0043          std::from_chars(p, p + std::strlen(p), v);
0044 
0045          return v;
0046       }
0047       else
0048       {
0049          return boost::lexical_cast<Real>(p);
0050       }
0051 
0052       #else
0053 
0054       return boost::lexical_cast<Real>(p);
0055 
0056       #endif
0057    }
0058    template <class Real>
0059    constexpr const char* convert_from_string(const char* p, const std::true_type&) noexcept
0060    {
0061       return p;
0062    }
0063    template <class Real>
0064    constexpr typename convert_from_string_result<Real>::type convert_from_string(const char* p) noexcept((std::is_constructible<Real, const char*>::value))
0065    {
0066       return convert_from_string<Real>(p, std::is_constructible<Real, const char*>());
0067    }
0068 
0069 } // namespace tools
0070 } // namespace math
0071 } // namespace boost
0072 
0073 #endif // BOOST_MATH_TOOLS_CONVERT_FROM_STRING_INCLUDED
0074