123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #ifndef BOOST_LOG_UTILITY_MANIPULATORS_INVOKE_HPP_INCLUDED_
- #define BOOST_LOG_UTILITY_MANIPULATORS_INVOKE_HPP_INCLUDED_
- #include <cstddef>
- #include <boost/core/enable_if.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/type_traits/remove_cv.hpp>
- #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
- #include <boost/type_traits/remove_reference.hpp>
- #endif
- #include <boost/log/detail/is_ostream.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- template< typename FunctionT >
- class invoke_manipulator
- {
- private:
- mutable FunctionT m_function;
- public:
-
- explicit invoke_manipulator(FunctionT const& func) :
- m_function(func)
- {
- }
- #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
-
- explicit invoke_manipulator(FunctionT&& func) :
- m_function(static_cast< FunctionT&& >(func))
- {
- }
- #endif
-
- template< typename StreamT >
- void output(StreamT& stream) const
- {
- m_function(stream);
- }
- };
- template< typename StreamT, typename FunctionT >
- inline typename boost::enable_if_c< log::aux::is_ostream< StreamT >::value, StreamT& >::type operator<< (StreamT& stream, invoke_manipulator< FunctionT > const& manip)
- {
- manip.output(stream);
- return stream;
- }
- #if !defined(BOOST_LOG_DOXYGEN_PASS)
- #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
- template< typename FunctionT >
- inline invoke_manipulator<
- typename boost::remove_cv<
- typename boost::remove_reference< FunctionT >::type
- >::type
- >
- invoke_manip(FunctionT&& func)
- {
- return invoke_manipulator<
- typename boost::remove_cv<
- typename boost::remove_reference< FunctionT >::type
- >::type
- >(static_cast< FunctionT&& >(func));
- }
- #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
- !defined(BOOST_NO_CXX14_GENERIC_LAMBDAS) && \
- !defined(BOOST_NO_CXX14_RETURN_TYPE_DEDUCTION)
- template< typename FunctionT, typename Arg0, typename... Args >
- inline auto invoke_manip(FunctionT&& func, Arg0&& arg0, Args&&... args)
- {
- return boost::log::invoke_manip
- (
- #if !defined(BOOST_LOG_NO_CXX20_PACK_EXPANSION_IN_LAMBDA_INIT_CAPTURE)
- [func = static_cast< FunctionT&& >(func), arg0 = static_cast< Arg0&& >(arg0), ...args = static_cast< Args&& >(args)](auto& stream) mutable
- #else
- [func, arg0, args...](auto& stream) mutable
- #endif
- {
- #if !defined(BOOST_MSVC) || BOOST_MSVC >= 1910
- static_cast< FunctionT&& >(func)(stream, static_cast< Arg0&& >(arg0), static_cast< Args&& >(args)...);
- #else
-
- func(stream, arg0, args...);
- #endif
- }
- );
- }
- #endif
- #else
- template< typename FunctionT >
- inline invoke_manipulator< typename boost::remove_cv< FunctionT >::type >
- invoke_manip(FunctionT const& func)
- {
- return invoke_manipulator< typename boost::remove_cv< FunctionT >::type >(func);
- }
- #endif
- #else
- template< typename FunctionT, typename... Args >
- invoke_manipulator< unspecified > invoke_manip(FunctionT&& func, Args&&... args);
- #endif
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|