lean2/src/util/freset.h
Leonardo de Moura 47c7bb1bde refactor(*): uses aliases for unordered_map and unordered_set
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-12-18 12:30:45 -08:00

38 lines
787 B
C++

/*
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include <utility>
namespace lean {
/**
\brief Template for simulating "fluid-resets".
Example:
<code>
{
freset<cache> reset(m_cache); // reset the cache inside this scope
} // restore original value of m_cache
</code>
\remark The reset is performed by creating a fresh value and performing a swap.
*/
template<typename T>
class freset {
T & m_ref;
T m_saved_value;
public:
freset(T & ref):
m_ref(ref) {
using std::swap;
swap(m_ref, m_saved_value);
}
~freset() {
using std::swap;
swap(m_ref, m_saved_value);
}
};
}