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   fun_ref.hpp
0009  * \author Andrey Semashev
0010  * \date   30.03.2008
0011  *
0012  * This header contains function object reference adapter. The adapter stores a reference to external
0013  * function object and forwards all calls to the referred function.
0014  */
0015 
0016 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_FUN_REF_HPP_INCLUDED_
0017 #define BOOST_LOG_UTILITY_FUNCTIONAL_FUN_REF_HPP_INCLUDED_
0018 
0019 #include <boost/log/detail/config.hpp>
0020 #include <boost/log/detail/header.hpp>
0021 
0022 #ifdef BOOST_HAS_PRAGMA_ONCE
0023 #pragma once
0024 #endif
0025 
0026 namespace boost {
0027 
0028 BOOST_LOG_OPEN_NAMESPACE
0029 
0030 //! Reference wrapper for function objects
0031 template< typename FunT >
0032 struct function_reference_wrapper
0033 {
0034     typedef typename FunT::result_type result_type;
0035 
0036     explicit function_reference_wrapper(FunT& fun) : m_Fun(fun) {}
0037 
0038     result_type operator() () const
0039     {
0040         return m_Fun();
0041     }
0042 
0043 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0044     template< typename... ArgsT >
0045     result_type operator() (ArgsT const&... args) const
0046     {
0047         return m_Fun(args...);
0048     }
0049 #else
0050     template< typename T >
0051     result_type operator() (T const& arg) const
0052     {
0053         return m_Fun(arg);
0054     }
0055 
0056     template< typename T1, typename T2 >
0057     result_type operator() (T1 const& arg1, T2 const& arg2) const
0058     {
0059         return m_Fun(arg1, arg2);
0060     }
0061 #endif
0062 
0063 private:
0064     FunT& m_Fun;
0065 };
0066 
0067 template< typename FunT >
0068 BOOST_FORCEINLINE function_reference_wrapper< FunT > fun_ref(FunT& fun)
0069 {
0070     return function_reference_wrapper< FunT >(fun);
0071 }
0072 
0073 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0074 
0075 } // namespace boost
0076 
0077 #include <boost/log/detail/footer.hpp>
0078 
0079 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_FUN_REF_HPP_INCLUDED_