1 // Copyright John Maddock 2016.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_MATH_TOOLS_CONVERT_FROM_STRING_INCLUDED
7 #define BOOST_MATH_TOOLS_CONVERT_FROM_STRING_INCLUDED
13 #include <boost/type_traits/is_constructible.hpp>
14 #include <boost/type_traits/conditional.hpp>
15 #include <boost/lexical_cast.hpp>
17 namespace boost{ namespace math{ namespace tools{
20 struct convert_from_string_result
22 typedef typename boost::conditional<boost::is_constructible<T, const char*>::value, const char*, T>::type type;
26 Real convert_from_string(const char* p, const mpl::false_&)
28 #ifdef BOOST_MATH_NO_LEXICAL_CAST
29 // This function should not compile, we don't have the necesary functionality to support it:
30 BOOST_STATIC_ASSERT(sizeof(Real) == 0);
32 return boost::lexical_cast<Real>(p);
36 BOOST_CONSTEXPR const char* convert_from_string(const char* p, const mpl::true_&) BOOST_NOEXCEPT
41 BOOST_CONSTEXPR typename convert_from_string_result<Real>::type convert_from_string(const char* p) BOOST_NOEXCEPT_IF((boost::is_constructible<Real, const char*>::value))
43 return convert_from_string<Real>(p, boost::is_constructible<Real, const char*>());
50 #endif // BOOST_MATH_TOOLS_CONVERT_FROM_STRING_INCLUDED