1/*
2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
6 */
7/*!
8 * \file bind.hpp
9 * \author Andrey Semashev
10 * \date 30.03.2008
11 *
12 * This header contains function object adapters.
13 * This is a lightweight alternative to what Boost.Phoenix and Boost.Bind provides.
14 */
15
16#ifndef BOOST_LOG_UTILITY_FUNCTIONAL_BIND_HPP_INCLUDED_
17#define BOOST_LOG_UTILITY_FUNCTIONAL_BIND_HPP_INCLUDED_
18
19#include <boost/type_traits/remove_cv.hpp>
20#include <boost/log/detail/config.hpp>
21#include <boost/log/detail/header.hpp>
22
23#ifdef BOOST_HAS_PRAGMA_ONCE
24#pragma once
25#endif
26
27namespace boost {
28
29BOOST_LOG_OPEN_NAMESPACE
30
31namespace aux {
32
33template< typename T >
34struct make_arg_type
35{
36 typedef T const& type;
37};
38
39template< typename T >
40struct make_arg_type< T& >
41{
42 typedef T& type;
43};
44
45} // namespace aux
46
47//! First argument binder
48template< typename FunT, typename FirstArgT >
49struct binder1st :
50 private FunT
51{
52 typedef typename FunT::result_type result_type;
53
54 binder1st(FunT const& fun, typename aux::make_arg_type< FirstArgT >::type arg) : FunT(fun), m_arg(arg) {}
55
56 result_type operator() () const
57 {
58 return FunT::operator()(m_arg);
59 }
60
61 template< typename T0 >
62 result_type operator() (T0 const& arg0) const
63 {
64 return FunT::operator()(m_arg, arg0);
65 }
66
67 template< typename T0, typename T1 >
68 result_type operator() (T0 const& arg0, T1 const& arg1) const
69 {
70 return FunT::operator()(m_arg, arg0, arg1);
71 }
72
73private:
74 FirstArgT m_arg;
75};
76
77//! First argument binder
78template< typename FunT, typename FirstArgT >
79struct binder1st< FunT&, FirstArgT >
80{
81 typedef typename remove_cv< FunT >::type::result_type result_type;
82
83 binder1st(FunT& fun, typename aux::make_arg_type< FirstArgT >::type arg) : m_fun(fun), m_arg(arg) {}
84
85 result_type operator() () const
86 {
87 return m_fun(m_arg);
88 }
89
90 template< typename T0 >
91 result_type operator() (T0 const& arg0) const
92 {
93 return m_fun(m_arg, arg0);
94 }
95
96 template< typename T0, typename T1 >
97 result_type operator() (T0 const& arg0, T1 const& arg1) const
98 {
99 return m_fun(m_arg, arg0, arg1);
100 }
101
102private:
103 FunT& m_fun;
104 FirstArgT m_arg;
105};
106
107template< typename FunT, typename FirstArgT >
108BOOST_FORCEINLINE binder1st< FunT, FirstArgT > bind1st(FunT fun, FirstArgT const& arg)
109{
110 return binder1st< FunT, FirstArgT >(fun, arg);
111}
112
113template< typename FunT, typename FirstArgT >
114BOOST_FORCEINLINE binder1st< FunT, FirstArgT > bind1st(FunT fun, FirstArgT& arg)
115{
116 return binder1st< FunT, FirstArgT >(fun, arg);
117}
118
119//! Second argument binder
120template< typename FunT, typename SecondArgT >
121struct binder2nd :
122 private FunT
123{
124 typedef typename FunT::result_type result_type;
125
126 binder2nd(FunT const& fun, typename aux::make_arg_type< SecondArgT >::type arg) : FunT(fun), m_arg(arg) {}
127
128 template< typename T >
129 result_type operator() (T const& arg) const
130 {
131 return FunT::operator()(arg, m_arg);
132 }
133
134 template< typename T0, typename T1 >
135 result_type operator() (T0 const& arg0, T1 const& arg1) const
136 {
137 return FunT::operator()(arg0, m_arg, arg1);
138 }
139
140private:
141 SecondArgT m_arg;
142};
143
144//! Second argument binder
145template< typename FunT, typename SecondArgT >
146struct binder2nd< FunT&, SecondArgT >
147{
148 typedef typename remove_cv< FunT >::type::result_type result_type;
149
150 binder2nd(FunT& fun, typename aux::make_arg_type< SecondArgT >::type arg) : m_fun(fun), m_arg(arg) {}
151
152 template< typename T >
153 result_type operator() (T const& arg) const
154 {
155 return m_fun(arg, m_arg);
156 }
157
158 template< typename T0, typename T1 >
159 result_type operator() (T0 const& arg0, T1 const& arg1) const
160 {
161 return m_fun(arg0, m_arg, arg1);
162 }
163
164private:
165 FunT& m_fun;
166 SecondArgT m_arg;
167};
168
169template< typename FunT, typename SecondArgT >
170BOOST_FORCEINLINE binder2nd< FunT, SecondArgT > bind2nd(FunT fun, SecondArgT const& arg)
171{
172 return binder2nd< FunT, SecondArgT >(fun, arg);
173}
174
175template< typename FunT, typename SecondArgT >
176BOOST_FORCEINLINE binder2nd< FunT, SecondArgT > bind2nd(FunT fun, SecondArgT& arg)
177{
178 return binder2nd< FunT, SecondArgT >(fun, arg);
179}
180
181//! Third argument binder
182template< typename FunT, typename ThirdArgT >
183struct binder3rd :
184 private FunT
185{
186 typedef typename FunT::result_type result_type;
187
188 binder3rd(FunT const& fun, typename aux::make_arg_type< ThirdArgT >::type arg) : FunT(fun), m_arg(arg) {}
189
190 template< typename T0, typename T1 >
191 result_type operator() (T0 const& arg0, T1 const& arg1) const
192 {
193 return FunT::operator()(arg0, arg1, m_arg);
194 }
195
196private:
197 ThirdArgT m_arg;
198};
199
200//! Third argument binder
201template< typename FunT, typename ThirdArgT >
202struct binder3rd< FunT&, ThirdArgT >
203{
204 typedef typename remove_cv< FunT >::type::result_type result_type;
205
206 binder3rd(FunT& fun, typename aux::make_arg_type< ThirdArgT >::type arg) : m_fun(fun), m_arg(arg) {}
207
208 template< typename T0, typename T1 >
209 result_type operator() (T0 const& arg0, T1 const& arg1) const
210 {
211 return m_fun(arg0, arg1, m_arg);
212 }
213
214private:
215 FunT& m_fun;
216 ThirdArgT m_arg;
217};
218
219template< typename FunT, typename ThirdArgT >
220BOOST_FORCEINLINE binder3rd< FunT, ThirdArgT > bind3rd(FunT fun, ThirdArgT const& arg)
221{
222 return binder3rd< FunT, ThirdArgT >(fun, arg);
223}
224
225template< typename FunT, typename ThirdArgT >
226BOOST_FORCEINLINE binder3rd< FunT, ThirdArgT > bind3rd(FunT fun, ThirdArgT& arg)
227{
228 return binder3rd< FunT, ThirdArgT >(fun, arg);
229}
230
231BOOST_LOG_CLOSE_NAMESPACE // namespace log
232
233} // namespace boost
234
235#include <boost/log/detail/footer.hpp>
236
237#endif // BOOST_LOG_UTILITY_FUNCTIONAL_BIND_HPP_INCLUDED_
238

source code of boost/libs/log/include/boost/log/utility/functional/bind.hpp