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)
8 * \file unary_function_terminal.hpp
9 * \author Andrey Semashev
12 * The header contains attribute value extractor adapter for constructing expression template terminals.
15 #ifndef BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_
16 #define BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_
18 #include <boost/mpl/bool.hpp>
19 #include <boost/utility/result_of.hpp>
20 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
21 #include <boost/phoenix/core/is_nullary.hpp>
22 #include <boost/phoenix/core/environment.hpp>
23 #include <boost/type_traits/remove_cv.hpp>
24 #include <boost/type_traits/remove_reference.hpp>
25 #include <boost/log/detail/config.hpp>
26 #include <boost/log/detail/copy_cv.hpp>
27 #include <boost/log/detail/custom_terminal_spec.hpp>
28 #include <boost/log/detail/header.hpp>
30 #ifdef BOOST_HAS_PRAGMA_ONCE
36 BOOST_LOG_OPEN_NAMESPACE
38 namespace expressions {
43 * \brief An adapter for a unary function to be used as a terminal in a Boost.Phoenix expression
45 * This class is an adapter between Boost.Phoenix expression invocation protocol and
46 * a unary function. It forwards the call to the base function, passing only the first argument
47 * from the original call. This allows to embed value extractors in template expressions.
49 template< typename FunT >
50 class unary_function_terminal
53 //! Adopted function type
54 typedef FunT function_type;
56 typedef unary_function_terminal< function_type > this_type;
59 //! Internal typedef for type categorization
60 typedef void _is_boost_log_terminal;
62 //! Function result type
66 template< typename ThisT, typename ContextT >
67 struct result< ThisT(ContextT) >
69 typedef typename remove_cv<
70 typename remove_reference< typename phoenix::result_of::env< ContextT >::type >::type
72 typedef typename env_type::args_type args_type;
73 typedef typename boost::log::aux::copy_cv< ThisT, function_type >::type cv_function_type;
75 typedef typename boost::result_of< cv_function_type(typename fusion::result_of::at_c< args_type, 0 >::type) >::type type;
83 //! Default constructor
84 BOOST_DEFAULTED_FUNCTION(unary_function_terminal(), {})
86 unary_function_terminal(unary_function_terminal const& that) : m_fun(that.m_fun) {}
87 //! Initializing constructor
88 template< typename ArgT1 >
89 explicit unary_function_terminal(ArgT1 const& arg1) : m_fun(arg1) {}
90 //! Initializing constructor
91 template< typename ArgT1, typename ArgT2 >
92 unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2) : m_fun(arg1, arg2) {}
93 //! Initializing constructor
94 template< typename ArgT1, typename ArgT2, typename ArgT3 >
95 unary_function_terminal(ArgT1 const& arg1, ArgT2 const& arg2, ArgT3 const& arg3) : m_fun(arg1, arg2, arg3) {}
97 //! The operator forwards the call to the base function
98 template< typename ContextT >
99 typename result< this_type(ContextT const&) >::type
100 operator() (ContextT const& ctx)
102 return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args()));
105 //! The operator forwards the call to the base function
106 template< typename ContextT >
107 typename result< const this_type(ContextT const&) >::type
108 operator() (ContextT const& ctx) const
110 return m_fun(fusion::at_c< 0 >(phoenix::env(ctx).args()));
116 } // namespace expressions
118 BOOST_LOG_CLOSE_NAMESPACE // namespace log
120 #ifndef BOOST_LOG_DOXYGEN_PASS
124 namespace result_of {
126 template< typename FunT >
127 struct is_nullary< custom_terminal< boost::log::expressions::aux::unary_function_terminal< FunT > > > :
132 } // namespace result_of
134 } // namespace phoenix
136 #endif // BOOST_LOG_DOXYGEN_PASS
140 #include <boost/log/detail/footer.hpp>
142 #endif // BOOST_LOG_DETAIL_UNARY_FUNCTION_TERMINAL_HPP_INCLUDED_