save_result.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 save_result.hpp
  9. * \author Andrey Semashev
  10. * \date 19.01.2013
  11. *
  12. * This header contains function object adapter that saves the result of the adopted function to an external variable.
  13. */
  14. #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_SAVE_RESULT_HPP_INCLUDED_
  15. #define BOOST_LOG_UTILITY_FUNCTIONAL_SAVE_RESULT_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #include <boost/log/detail/header.hpp>
  18. #ifdef BOOST_HAS_PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. namespace boost {
  22. BOOST_LOG_OPEN_NAMESPACE
  23. //! Function object wrapper for saving the adopted function object result
  24. template< typename FunT, typename AssigneeT >
  25. struct save_result_wrapper
  26. {
  27. typedef void result_type;
  28. save_result_wrapper(FunT fun, AssigneeT& assignee) : m_fun(fun), m_assignee(assignee) {}
  29. template< typename ArgT >
  30. result_type operator() (ArgT const& arg) const
  31. {
  32. m_assignee = m_fun(arg);
  33. }
  34. private:
  35. FunT m_fun;
  36. AssigneeT& m_assignee;
  37. };
  38. template< typename FunT, typename AssigneeT >
  39. BOOST_FORCEINLINE save_result_wrapper< FunT, AssigneeT > save_result(FunT const& fun, AssigneeT& assignee)
  40. {
  41. return save_result_wrapper< FunT, AssigneeT >(fun, assignee);
  42. }
  43. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  44. } // namespace boost
  45. #include <boost/log/detail/footer.hpp>
  46. #endif // BOOST_LOG_UTILITY_FUNCTIONAL_SAVE_RESULT_HPP_INCLUDED_