
Peter Dimov wrote:
Andrey Semashev wrote:
So, there was a really interesting and hot discussion about namings. Many opinions were expressed and I'd like to make some roundup.
I still think that the question "should X be included at all" is slightly more fundamental than "should X be named rearm, protect, or on". But this may be just me.
I'm sorry I didn't answer directly to you, but I wrote this in one of the descussion threads: The more common use case is to create initially disabled guard and then, depending on some condition, activate it. I've had the need of such functionality several times. The example may be made up. Imagine we have some function that plays the role of a common entry point that dispatches objects of different types. For simplicity all objects support interface IObject that have a method GetType. The objects should be dispatched to different another entities depending on their type. But for some objects some post-actions should be made. void Entry(IObject* pObj) { scope_guard g = make_guard(&PostActions, guard::disarmed); switch (pObj->GetType()) { case eType1: m_pEntity1->Process(pObj); // may throw break; case eType2: g.arm(); m_pEntity2->Process(pObj); // may throw break; case eType3: g.arm(); m_pEntity3->Process(pObj); // may throw break; }; } Another example. Assume you have to operate with some non-trivial object. Something like that: void foo(CObject const& obj) { scope_guard g = make_guard(&PostActions, guard::disarmed); obj.foo1(); if (obj.is_ok()) { obj.foo2(param); if (obj.foo3(param)) do_smth(); else g.arm(); obj.foo4(); } do_smth_more(); } Both examples are very simplified but I hope they show the picture.