mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 20:05:51 +00:00
mv util/lp to math/lp
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
b6513b8e2d
commit
33cbd29ed0
150 changed files with 524 additions and 479 deletions
84
src/math/lp/stacked_value.h
Normal file
84
src/math/lp/stacked_value.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*++
|
||||
Copyright (c) 2017 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
<name>
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Lev Nachmanson (levnach)
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
// add to value the stack semantics
|
||||
#include <stack>
|
||||
namespace lp {
|
||||
template <typename T> class stacked_value {
|
||||
T m_value;
|
||||
std::stack<T> m_stack;
|
||||
public:
|
||||
void push() {
|
||||
m_stack.push(m_value);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
m_stack.clear();
|
||||
}
|
||||
|
||||
unsigned stack_size() const {
|
||||
return static_cast<unsigned>(m_stack.size());
|
||||
}
|
||||
|
||||
void pop() {
|
||||
pop(1);
|
||||
}
|
||||
void pop(unsigned k) {
|
||||
while (k-- > 0) {
|
||||
if (m_stack.empty())
|
||||
return;
|
||||
m_value = m_stack.top();
|
||||
m_stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
stacked_value() {}
|
||||
stacked_value(const T& m) {
|
||||
m_value = m;
|
||||
}
|
||||
stacked_value(const T&& m) {
|
||||
m_value = std::move(m);
|
||||
}
|
||||
|
||||
T& operator=(T arg) { // copy/move constructor
|
||||
m_value = arg;
|
||||
return m_value;
|
||||
}
|
||||
|
||||
operator T&() {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
operator const T&() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
T & operator()() {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
const T & operator()() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue