On Thu, 2010-04-22, Yannick Tremblay wrote:
> In article <>,
> Leigh Johnston <> wrote:
>>
>>
>>"Keith H Duggar" <> wrote in message
>>news:18b3b1fe-8937-4bfe-9dfc-...
>>> ScoreGuard:
>>>
>>> http://www.drdobbs.com/cpp/184403758...OSKH4ATMY32JVN
>>>
>>> and related ideas. You can write little wrapper functions of all sorts
>>> and construct ScopeGuards of them. You can also generalize it a bit
>>> and do without the *Obj* variants by simplifying ScopeGuard and
>>> combining it with Don Clugston's FastDelegates:
>>>
>>> http://www.codeproject.com/kb/cpp/FastDelegate.aspx
>>>
>>> KHD
>>
>>Whilst I agree that ScopeGuards can be useful it is important to note
>>however that their overuse may be an indication of a lack of class based
>>abstractions (I am primarily an OO programmer, not a procedural programmer).
>
> But the OP query relates to interacting with libc functions like
> open(), fopen(), popen(), pipe(), etc. ScopeGuards are pretty close
> to ideal to make it easy to write exception safe C++ code that
> interact with lower level C libraries.
But if you're wrapping a C library, I guess you can often find some
abstraction level where it makes sense to introduce a class, and then
you use such objects instead of thinly wrapped (in this case) file
descriptors. I assume that's what Leigh meant.
For example, I think it's generally better to wrap pipe() in some way
suited to your specific application, rather than to just fix the
possible resource leak.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .