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

📄 functional.hpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 HPP
📖 第 1 页 / 共 2 页
字号:
////////////////////////////////////////////////////////////////////////////////// \file functional.hpp/////  Copyright 2005 Eric Niebler. 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)#ifndef BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005#define BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005#include <limits>#include <functional>#include <boost/mpl/if.hpp>#include <boost/mpl/and.hpp>#include <boost/type_traits/remove_const.hpp>#include <boost/type_traits/add_reference.hpp>#include <boost/type_traits/is_empty.hpp>#include <boost/type_traits/is_integral.hpp>#include <boost/type_traits/is_floating_point.hpp>#include <boost/utility/enable_if.hpp>#include <boost/typeof/typeof.hpp>#include <boost/accumulators/numeric/functional_fwd.hpp>#include <boost/accumulators/numeric/detail/function1.hpp>#include <boost/accumulators/numeric/detail/function2.hpp>#include <boost/accumulators/numeric/detail/pod_singleton.hpp>#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT# include <boost/accumulators/numeric/functional/vector.hpp>#endif#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT# include <boost/accumulators/numeric/functional/valarray.hpp>#endif#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT# include <boost/accumulators/numeric/functional/complex.hpp>#endif/// INTERNAL ONLY///#define BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED#ifdef BOOST_NUMERIC_FUNCTIONAL_DOXYGEN_INVOKED// Hack to make Doxygen show the inheritance relationships/// INTERNAL ONLY///namespace std{    /// INTERNAL ONLY    ///    template<class Arg, class Ret> struct unary_function {};    /// INTERNAL ONLY    ///    template<class Left, class Right, class Ret> struct binary_function {};}#endifnamespace boost { namespace numeric{    namespace functional    {        /// INTERNAL ONLY        ///        template<typename A0, typename A1>        struct are_integral          : mpl::and_<is_integral<A0>, is_integral<A1> >        {};        template<typename Left, typename Right>        struct left_ref        {            typedef Left &type;        };        namespace detail        {            template<typename T>            T &lvalue_of();        }    }    // TODO: handle complex weight, valarray, MTL vectors    /// INTERNAL ONLY    ///#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(Name, Op)                                      \    namespace functional                                                                        \    {                                                                                           \        template<typename Arg>                                                                  \        struct result_of_ ## Name                                                               \        {                                                                                       \            BOOST_TYPEOF_NESTED_TYPEDEF_TPL(                                                    \                nested                                                                          \              , Op boost::numeric::functional::detail::lvalue_of<Arg>()                         \            )                                                                                   \            typedef typename nested::type type;                                                 \        };                                                                                      \        template<typename Arg, typename EnableIf>                                               \        struct Name ## _base                                                                    \          : std::unary_function<                                                                \                typename remove_const<Arg>::type                                                \              , typename result_of_ ## Name<Arg>::type                                          \            >                                                                                   \        {                                                                                       \            typename result_of_ ## Name<Arg>::type operator ()(Arg &arg) const                  \            {                                                                                   \                return Op arg;                                                                  \            }                                                                                   \        };                                                                                      \        template<typename Arg, typename ArgTag>                                                 \        struct Name                                                                             \          : Name ## _base<Arg, void>                                                            \        {};                                                                                     \    }                                                                                           \    namespace op                                                                                \    {                                                                                           \        struct Name                                                                             \          : boost::detail::function1<functional::Name<_, functional::tag<_> > >                 \        {};                                                                                     \    }                                                                                           \    namespace                                                                                   \    {                                                                                           \        op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance;                \    }                                                                                           \    /**/    /// INTERNAL ONLY    ///#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(Name, Op, RetType)                            \    namespace functional                                                                        \    {                                                                                           \        template<typename Left, typename Right, typename EnableIf>                              \        struct result_of_ ## Name                                                               \        {                                                                                       \            RetType(Left, Op, Right)                                                            \        };                                                                                      \        template<typename Left, typename Right, typename EnableIf>                              \        struct Name ## _base                                                                    \          : std::binary_function<                                                               \                typename remove_const<Left>::type                                               \              , typename remove_const<Right>::type                                              \              , typename result_of_ ## Name<Left, Right>::type                                  \            >                                                                                   \        {                                                                                       \            typename result_of_ ## Name<Left, Right>::type                                      \            operator ()(Left &left, Right &right) const                                         \            {                                                                                   \                return left Op right;                                                           \            }                                                                                   \        };                                                                                      \        template<typename Left, typename Right, typename LeftTag, typename RightTag>            \        struct Name                                                                             \          : Name ## _base<Left, Right, void>                                                    \        {};                                                                                     \    }                                                                                           \    namespace op                                                                                \    {                                                                                           \        struct Name                                                                             \          : boost::detail::function2<                                                           \                functional::Name<_1, _2, functional::tag<_1>, functional::tag<_2> >             \            >                                                                                   \        {};                                                                                     \    }                                                                                           \    namespace                                                                                   \    {                                                                                           \        op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance;                \    }                                                                                           \    /**/    /// INTERNAL ONLY    ///#define BOOST_NUMERIC_FUNCTIONAL_DEDUCED(Left, Op, Right)                                       \    BOOST_TYPEOF_NESTED_TYPEDEF_TPL(                                                            \        nested                                                                                  \      , boost::numeric::functional::detail::lvalue_of<Left>() Op                                \        boost::numeric::functional::detail::lvalue_of<Right>()                                  \    )                                                                                           \    typedef typename nested::type type;                                                         \    /**/    /// INTERNAL ONLY    ///#define BOOST_NUMERIC_FUNCTIONAL_LEFT(Left, Op, Right)                                          \    typedef Left &type;                                                                         \    /**/    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(plus, +, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(minus, -, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(multiplies, *, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(divides, /, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(modulus, %, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(greater, >, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(greater_equal, >=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(less, <, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(less_equal, <=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(equal_to, ==, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(not_equal_to, !=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(assign, =, BOOST_NUMERIC_FUNCTIONAL_LEFT)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(plus_assign, +=, BOOST_NUMERIC_FUNCTIONAL_LEFT)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(minus_assign, -=, BOOST_NUMERIC_FUNCTIONAL_LEFT)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(multiplies_assign, *=, BOOST_NUMERIC_FUNCTIONAL_LEFT)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(divides_assign, /=, BOOST_NUMERIC_FUNCTIONAL_LEFT)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(modulus_assign, %=, BOOST_NUMERIC_FUNCTIONAL_LEFT)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(unary_plus, +)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(unary_minus, -)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(complement, ~)    BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(logical_not, !)#undef BOOST_NUMERIC_FUNCTIONAL_LEFT#undef BOOST_NUMERIC_FUNCTIONAL_DEDUCED#undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP#undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP    namespace functional    {        template<typename Left, typename Right, typename EnableIf>        struct min_assign_base          : std::binary_function<Left, Right, void>        {            void operator ()(Left &left, Right &right) const            {                if(numeric::less(right, left))                {                    left = right;                }            }        };        template<typename Left, typename Right, typename EnableIf>        struct max_assign_base          : std::binary_function<Left, Right, void>        {            void operator ()(Left &left, Right &right) const            {                if(numeric::greater(right, left))                {                    left = right;                }            }        };        template<typename Left, typename Right, typename EnableIf>        struct average_base          : functional::divides<Left, Right>

⌨️ 快捷键说明

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