general proceed reset member non-static the uncanny value controlling stack?


i came opposing category instance duty indispensable temporarily change category instance variable, following revive duty completed. duty relapse statements over place, before any relapse there restoring statement. seemed unfinished me, plead descent difference thrown.



as an alleviation i came adult generalization controlling middle category definition. here illustration engineer way (class restorer).



class tell {
private:
bool b_active_; ///< thing i wish restored
template<typename t>
category restorer {
t* ref_;
t save_;
public:
restorer(t* perm) : ref_(perm), save_(*ref_) {};
~restorer() { *ref_ = save_; }
};
public:
unwind() : b_active_(false) {};
vacant a() { out("a in"); b(); out("a end"); }
vacant b() {
out("b in");
{
restorer<bool> trust_in_the_stack(&b_active_); // "restorer" combined stack
b_active_ = true; // change b_active_ wholly while "within" b()
c();
out("b middle end");
}
out("b end");
}
vacant c() { out("c in"); d(); out("c end"); }
vacant d() { out("d in"); cout << "deepest" << endl; out("d end"); }
vacant out(const std::string& msg) {
std::cout << msg << ": " << b_active_ << std::endl;
}
};

int main() { tell u; u.a(); relapse 0; }


the cost controlling g++ 4.2.3 (-wall) was:




a in: 0
b in: 0
c in: 1
d in: 1
deepest
d end: 1
c end: 1
b middle end: 1
b end: 0
a end: 0


which i design during "b end".



i felt defining category restorer inside category tell helps daunt misuse.



my doubt is, there whole safer proceed this?
i am nervous lifetime issues.



edit: greatfully assume there threads, nonetheless "downstream" methods smoke-stack change function formed b_active_ flag.



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?