// Copyright 2012, Matthias Andreas Benkard. #pragma once #ifndef DYNVARS_IMPL_HPP #define DYNVARS_IMPL_HPP #include #include #include #include #include #include #include #include "dynvars.hpp" namespace dynvars { using namespace ::std; template dynvar::dynvar(T val) { this->push(val); } template dynvar& dynvar::operator =(T val) { if (!value_stack.empty()) { this->pop(); } this->push(val); return *this; } template void dynvar::push(T val) { value_stack.push_front(val); } template void dynvar::pop() { value_stack.pop_front(); } template dynvar::operator bool() const { return !value_stack.empty(); } template T& dynvar::operator *() { return value_stack.front(); } template T* dynvar::operator ->() { return &value_stack.front(); } template dyn::dyn(dynvar& var, R val) : myvar(var) { myvar.push(val); } template dyn::~dyn() { myvar.pop(); } template T with(dynvar& var, R val, function f) { dyn d_(var, val); return f(); } } #endif //DYNVARS_IMPL_HPP