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 
8 #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005
9 #define BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005
10 
11 // MS compatible compilers support #pragma once
12 #if defined(_MSC_VER)
13 # pragma once
14 #endif
15 
16 #include <boost/noncopyable.hpp>
17 
18 namespace boost { namespace xpressive { namespace detail
19 {
20 
21     template<typename T>
22     struct save_restore
23       : private noncopyable
24     {
save_restoreboost::xpressive::detail::save_restore25         explicit save_restore(T &t)
26           : ref(t)
27           , val(t)
28         {
29         }
30 
save_restoreboost::xpressive::detail::save_restore31         save_restore(T &t, T const &n)
32           : ref(t)
33           , val(t)
34         {
35             this->ref = n;
36         }
37 
~save_restoreboost::xpressive::detail::save_restore38         ~save_restore()
39         {
40             this->ref = this->val;
41         }
42 
restoreboost::xpressive::detail::save_restore43         void restore()
44         {
45             this->ref = this->val;
46         }
47 
48     private:
49         T &ref;
50         T const val;
51     };
52 
53 }}}
54 
55 #endif
56