/src/contrib/boost-1.52.0/boost/xpressive/detail/utility/save_restore.hpp

https://gitlab.com/tylerluo/pythonocc · C++ Header · 55 lines · 37 code · 11 blank · 7 comment · 1 complexity · 2331eed37990f26b78ab4a95e1ace99c MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // save_restore.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  11. # pragma once
  12. #endif
  13. #include <boost/noncopyable.hpp>
  14. namespace boost { namespace xpressive { namespace detail
  15. {
  16. template<typename T>
  17. struct save_restore
  18. : private noncopyable
  19. {
  20. explicit save_restore(T &t)
  21. : ref(t)
  22. , val(t)
  23. {
  24. }
  25. save_restore(T &t, T const &n)
  26. : ref(t)
  27. , val(t)
  28. {
  29. this->ref = n;
  30. }
  31. ~save_restore()
  32. {
  33. this->ref = this->val;
  34. }
  35. void restore()
  36. {
  37. this->ref = this->val;
  38. }
  39. private:
  40. T &ref;
  41. T const val;
  42. };
  43. }}}
  44. #endif