Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/lexical_cast/try_lexical_convert.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright Kevlin Henney, 2000-2005.
0002 // Copyright Alexander Nasonov, 2006-2010.
0003 // Copyright Antony Polukhin, 2011-2024.
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See
0006 // accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // what:  lexical_cast custom keyword cast
0010 // who:   contributed by Kevlin Henney,
0011 //        enhanced with contributions from Terje Slettebo,
0012 //        with additional fixes and suggestions from Gennaro Prota,
0013 //        Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
0014 //        Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
0015 //        Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
0016 // when:  November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
0017 
0018 #ifndef BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
0019 #define BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
0020 
0021 #include <boost/config.hpp>
0022 #ifdef BOOST_HAS_PRAGMA_ONCE
0023 #   pragma once
0024 #endif
0025 
0026 #include <boost/type_traits/conditional.hpp>
0027 #include <boost/type_traits/is_arithmetic.hpp>
0028 
0029 #include <boost/lexical_cast/detail/buffer_view.hpp>
0030 #include <boost/lexical_cast/detail/is_character.hpp>
0031 #include <boost/lexical_cast/detail/converter_numeric.hpp>
0032 #include <boost/lexical_cast/detail/converter_lexical.hpp>
0033 
0034 namespace boost {
0035     namespace detail
0036     {
0037         template<typename Target, typename Source>
0038         using is_arithmetic_and_not_xchars = boost::integral_constant<
0039             bool,
0040             !(boost::detail::is_character<Target>::value) &&
0041                 !(boost::detail::is_character<Source>::value) &&
0042                 boost::is_arithmetic<Source>::value &&
0043                 boost::is_arithmetic<Target>::value
0044         >;
0045     }
0046 
0047     namespace conversion { namespace detail {
0048 
0049         template <typename Target, typename Source>
0050         inline bool try_lexical_convert(const Source& arg, Target& result)
0051         {
0052             static_assert(
0053                 !boost::is_volatile<Source>::value,
0054                 "Boost.LexicalCast does not support volatile input");
0055 
0056             typedef typename boost::detail::array_to_pointer_decay<Source>::type src;
0057 
0058             typedef boost::detail::is_arithmetic_and_not_xchars<Target, src >
0059                 shall_we_copy_with_dynamic_check_t;
0060 
0061             typedef typename boost::conditional<
0062                  shall_we_copy_with_dynamic_check_t::value,
0063                  boost::detail::dynamic_num_converter_impl<Target, src >,
0064                  boost::detail::lexical_converter_impl<Target, src >
0065             >::type caster_type;
0066 
0067             return caster_type::try_convert(arg, result);
0068         }
0069 
0070         template <typename Target, typename CharacterT>
0071         inline bool try_lexical_convert(const CharacterT* chars, std::size_t count, Target& result)
0072         {
0073             static_assert(
0074                 boost::detail::is_character<CharacterT>::value,
0075                 "This overload of try_lexical_convert is meant to be used only with arrays of characters."
0076             );
0077             return ::boost::conversion::detail::try_lexical_convert(
0078                 ::boost::conversion::detail::make_buffer_view(chars, chars + count),
0079                 result
0080             );
0081         }
0082 
0083     }} // namespace conversion::detail
0084 
0085     namespace conversion {
0086         // ADL barrier
0087         using ::boost::conversion::detail::try_lexical_convert;
0088     }
0089 
0090 } // namespace boost
0091 
0092 #endif // BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
0093