Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:27

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   bind.hpp
0009  * \author Andrey Semashev
0010  * \date   30.03.2008
0011  *
0012  * This header contains function object adapters.
0013  * This is a lightweight alternative to what Boost.Phoenix and Boost.Bind provides.
0014  */
0015 
0016 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_BIND_HPP_INCLUDED_
0017 #define BOOST_LOG_UTILITY_FUNCTIONAL_BIND_HPP_INCLUDED_
0018 
0019 #include <boost/type_traits/remove_cv.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/detail/header.hpp>
0022 
0023 #ifdef BOOST_HAS_PRAGMA_ONCE
0024 #pragma once
0025 #endif
0026 
0027 namespace boost {
0028 
0029 BOOST_LOG_OPEN_NAMESPACE
0030 
0031 namespace aux {
0032 
0033 template< typename T >
0034 struct make_arg_type
0035 {
0036     typedef T const& type;
0037 };
0038 
0039 template< typename T >
0040 struct make_arg_type< T& >
0041 {
0042     typedef T& type;
0043 };
0044 
0045 } // namespace aux
0046 
0047 //! First argument binder
0048 template< typename FunT, typename FirstArgT >
0049 struct binder1st :
0050     private FunT
0051 {
0052     typedef typename FunT::result_type result_type;
0053 
0054     binder1st(FunT const& fun, typename aux::make_arg_type< FirstArgT >::type arg) : FunT(fun), m_arg(arg) {}
0055 
0056     result_type operator() () const
0057     {
0058         return FunT::operator()(m_arg);
0059     }
0060 
0061     template< typename T0 >
0062     result_type operator() (T0 const& arg0) const
0063     {
0064         return FunT::operator()(m_arg, arg0);
0065     }
0066 
0067     template< typename T0, typename T1 >
0068     result_type operator() (T0 const& arg0, T1 const& arg1) const
0069     {
0070         return FunT::operator()(m_arg, arg0, arg1);
0071     }
0072 
0073 private:
0074     FirstArgT m_arg;
0075 };
0076 
0077 //! First argument binder
0078 template< typename FunT, typename FirstArgT >
0079 struct binder1st< FunT&, FirstArgT >
0080 {
0081     typedef typename remove_cv< FunT >::type::result_type result_type;
0082 
0083     binder1st(FunT& fun, typename aux::make_arg_type< FirstArgT >::type arg) : m_fun(fun), m_arg(arg) {}
0084 
0085     result_type operator() () const
0086     {
0087         return m_fun(m_arg);
0088     }
0089 
0090     template< typename T0 >
0091     result_type operator() (T0 const& arg0) const
0092     {
0093         return m_fun(m_arg, arg0);
0094     }
0095 
0096     template< typename T0, typename T1 >
0097     result_type operator() (T0 const& arg0, T1 const& arg1) const
0098     {
0099         return m_fun(m_arg, arg0, arg1);
0100     }
0101 
0102 private:
0103     FunT& m_fun;
0104     FirstArgT m_arg;
0105 };
0106 
0107 template< typename FunT, typename FirstArgT >
0108 BOOST_FORCEINLINE binder1st< FunT, FirstArgT > bind1st(FunT fun, FirstArgT const& arg)
0109 {
0110     return binder1st< FunT, FirstArgT >(fun, arg);
0111 }
0112 
0113 template< typename FunT, typename FirstArgT >
0114 BOOST_FORCEINLINE binder1st< FunT, FirstArgT > bind1st(FunT fun, FirstArgT& arg)
0115 {
0116     return binder1st< FunT, FirstArgT >(fun, arg);
0117 }
0118 
0119 //! Second argument binder
0120 template< typename FunT, typename SecondArgT >
0121 struct binder2nd :
0122     private FunT
0123 {
0124     typedef typename FunT::result_type result_type;
0125 
0126     binder2nd(FunT const& fun, typename aux::make_arg_type< SecondArgT >::type arg) : FunT(fun), m_arg(arg) {}
0127 
0128     template< typename T >
0129     result_type operator() (T const& arg) const
0130     {
0131         return FunT::operator()(arg, m_arg);
0132     }
0133 
0134     template< typename T0, typename T1 >
0135     result_type operator() (T0 const& arg0, T1 const& arg1) const
0136     {
0137         return FunT::operator()(arg0, m_arg, arg1);
0138     }
0139 
0140 private:
0141     SecondArgT m_arg;
0142 };
0143 
0144 //! Second argument binder
0145 template< typename FunT, typename SecondArgT >
0146 struct binder2nd< FunT&, SecondArgT >
0147 {
0148     typedef typename remove_cv< FunT >::type::result_type result_type;
0149 
0150     binder2nd(FunT& fun, typename aux::make_arg_type< SecondArgT >::type arg) : m_fun(fun), m_arg(arg) {}
0151 
0152     template< typename T >
0153     result_type operator() (T const& arg) const
0154     {
0155         return m_fun(arg, m_arg);
0156     }
0157 
0158     template< typename T0, typename T1 >
0159     result_type operator() (T0 const& arg0, T1 const& arg1) const
0160     {
0161         return m_fun(arg0, m_arg, arg1);
0162     }
0163 
0164 private:
0165     FunT& m_fun;
0166     SecondArgT m_arg;
0167 };
0168 
0169 template< typename FunT, typename SecondArgT >
0170 BOOST_FORCEINLINE binder2nd< FunT, SecondArgT > bind2nd(FunT fun, SecondArgT const& arg)
0171 {
0172     return binder2nd< FunT, SecondArgT >(fun, arg);
0173 }
0174 
0175 template< typename FunT, typename SecondArgT >
0176 BOOST_FORCEINLINE binder2nd< FunT, SecondArgT > bind2nd(FunT fun, SecondArgT& arg)
0177 {
0178     return binder2nd< FunT, SecondArgT >(fun, arg);
0179 }
0180 
0181 //! Third argument binder
0182 template< typename FunT, typename ThirdArgT >
0183 struct binder3rd :
0184     private FunT
0185 {
0186     typedef typename FunT::result_type result_type;
0187 
0188     binder3rd(FunT const& fun, typename aux::make_arg_type< ThirdArgT >::type arg) : FunT(fun), m_arg(arg) {}
0189 
0190     template< typename T0, typename T1 >
0191     result_type operator() (T0 const& arg0, T1 const& arg1) const
0192     {
0193         return FunT::operator()(arg0, arg1, m_arg);
0194     }
0195 
0196 private:
0197     ThirdArgT m_arg;
0198 };
0199 
0200 //! Third argument binder
0201 template< typename FunT, typename ThirdArgT >
0202 struct binder3rd< FunT&, ThirdArgT >
0203 {
0204     typedef typename remove_cv< FunT >::type::result_type result_type;
0205 
0206     binder3rd(FunT& fun, typename aux::make_arg_type< ThirdArgT >::type arg) : m_fun(fun), m_arg(arg) {}
0207 
0208     template< typename T0, typename T1 >
0209     result_type operator() (T0 const& arg0, T1 const& arg1) const
0210     {
0211         return m_fun(arg0, arg1, m_arg);
0212     }
0213 
0214 private:
0215     FunT& m_fun;
0216     ThirdArgT m_arg;
0217 };
0218 
0219 template< typename FunT, typename ThirdArgT >
0220 BOOST_FORCEINLINE binder3rd< FunT, ThirdArgT > bind3rd(FunT fun, ThirdArgT const& arg)
0221 {
0222     return binder3rd< FunT, ThirdArgT >(fun, arg);
0223 }
0224 
0225 template< typename FunT, typename ThirdArgT >
0226 BOOST_FORCEINLINE binder3rd< FunT, ThirdArgT > bind3rd(FunT fun, ThirdArgT& arg)
0227 {
0228     return binder3rd< FunT, ThirdArgT >(fun, arg);
0229 }
0230 
0231 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0232 
0233 } // namespace boost
0234 
0235 #include <boost/log/detail/footer.hpp>
0236 
0237 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_BIND_HPP_INCLUDED_