⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numeric_utils.hpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 HPP
字号:
/*=============================================================================    Copyright (c) 2001-2007 Joel de Guzman    Distributed under the Boost Software License, Version 1.0. (See accompanying    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)==============================================================================*/#if !defined(BOOST_SPIRIT_NUMERIC_UTILS_APR_17_2006_0830AM)#define BOOST_SPIRIT_NUMERIC_UTILS_APR_17_2006_0830AM#include <boost/spirit/home/qi/numeric/detail/numeric_utils.hpp>#include <boost/assert.hpp>#include <boost/mpl/assert.hpp>namespace boost { namespace spirit { namespace qi{    ///////////////////////////////////////////////////////////////////////    //  Extract the prefix sign (- or +), return true if a '-' was found    ///////////////////////////////////////////////////////////////////////    template <typename Iterator>    inline bool    extract_sign(Iterator& first, Iterator const& last)    {        BOOST_ASSERT(first != last); // precondition        // Extract the sign        bool neg = *first == '-';        if (neg || (*first == '+'))        {            ++first;            return neg;        }        return false;    }    ///////////////////////////////////////////////////////////////////////    // Low level unsigned integer parser    ///////////////////////////////////////////////////////////////////////    template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits      , bool Accumulate = false>    struct extract_uint    {        // check template parameter 'Radix' for validity        BOOST_MPL_ASSERT_MSG(            Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,            not_supported_radix, ());        template <typename Iterator, typename Attribute>        static bool call(Iterator& first, Iterator const& last, Attribute& attr)        {            typedef detail::extract_int<                T              , Radix              , MinDigits              , MaxDigits              , detail::positive_accumulator<Radix>              , Accumulate>            extract_type;            Iterator save = first;            if (!extract_type::parse(first, last, attr))            {                first = save;                return false;            }            return true;        }    };    ///////////////////////////////////////////////////////////////////////    // Low level signed integer parser    ///////////////////////////////////////////////////////////////////////    template <typename T, unsigned Radix, unsigned MinDigits, int MaxDigits>    struct extract_int    {        // check template parameter 'Radix' for validity        BOOST_MPL_ASSERT_MSG(            Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,            not_supported_radix, ());        template <typename Iterator, typename Attribute>        static bool call(Iterator& first, Iterator const& last, Attribute& attr)        {            if (first == last)                return false;            typedef detail::extract_int<                T, Radix, MinDigits, MaxDigits>            extract_pos_type;            typedef detail::extract_int<                T, Radix, MinDigits, MaxDigits, detail::negative_accumulator<Radix> >            extract_neg_type;            Iterator save = first;            bool hit = extract_sign(first, last);            if (hit)                hit = extract_neg_type::parse(first, last, attr);            else                hit = extract_pos_type::parse(first, last, attr);            if (!hit)            {                first = save;                return false;            }            return true;        }    };}}}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -