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 fun_ref.hpp 9 * \author Andrey Semashev 10 * \date 30.03.2008 11 * 12 * This header contains function object reference adapter. The adapter stores a reference to external 13 * function object and forwards all calls to the referred function. 14 */ 15 16 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_FUN_REF_HPP_INCLUDED_ 17 #define BOOST_LOG_UTILITY_FUNCTIONAL_FUN_REF_HPP_INCLUDED_ 18 19 #include <boost/log/detail/config.hpp> 20 #include <boost/log/detail/header.hpp> 21 22 #ifdef BOOST_HAS_PRAGMA_ONCE 23 #pragma once 24 #endif 25 26 namespace boost { 27 28 BOOST_LOG_OPEN_NAMESPACE 29 30 //! Reference wrapper for function objects 31 template< typename FunT > 32 struct function_reference_wrapper 33 { 34 typedef typename FunT::result_type result_type; 35 function_reference_wrapperboost::function_reference_wrapper36 explicit function_reference_wrapper(FunT& fun) : m_Fun(fun) {} 37 operator ()boost::function_reference_wrapper38 result_type operator() () const 39 { 40 return m_Fun(); 41 } 42 43 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 44 template< typename... ArgsT > operator ()boost::function_reference_wrapper45 result_type operator() (ArgsT const&... args) const 46 { 47 return m_Fun(args...); 48 } 49 #else 50 template< typename T > operator ()boost::function_reference_wrapper51 result_type operator() (T const& arg) const 52 { 53 return m_Fun(arg); 54 } 55 56 template< typename T1, typename T2 > operator ()boost::function_reference_wrapper57 result_type operator() (T1 const& arg1, T2 const& arg2) const 58 { 59 return m_Fun(arg1, arg2); 60 } 61 #endif 62 63 private: 64 FunT& m_Fun; 65 }; 66 67 template< typename FunT > fun_ref(FunT & fun)68BOOST_FORCEINLINE function_reference_wrapper< FunT > fun_ref(FunT& fun) 69 { 70 return function_reference_wrapper< FunT >(fun); 71 } 72 73 BOOST_LOG_CLOSE_NAMESPACE // namespace log 74 75 } // namespace boost 76 77 #include <boost/log/detail/footer.hpp> 78 79 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_FUN_REF_HPP_INCLUDED_ 80