|
Boost : |
From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2003-09-24 15:28:25
At 22:02 2003-09-24, Dumbnose wrote:
>I hadn't set out to do this. I couldn't find the download for the code from
>the original article. So, I was just sitting at a coffe shop to reimplement
>it as described in the article. I got sick of cutting and pasting and
>decided to do this instead. I only tried it with Visual C++ 7.1 so far.
>Once I get a few minutes, I will check it with Comeau and GCC (I've been at
>work for two days straight, so I'm a little slap happy right now). I am
>attaching my implementation as well as the basic tests I created for it.
This is a very inefficient implementation. There is really no point in using
a boost::function<> when the class can just as well be a template.
FWIW, here's the scopeguard implementation that I use:
namespace detail
{
class guard_base
{
public:
guard_base()
: m_dismissed(false)
{}
void dismiss() const
{ m_dismissed = true; }
protected:
mutable bool m_dismissed;
};
template<class T>
class guard_impl : public guard_base
{
public:
explicit guard_impl(const T& x)
: m_action(x)
{}
~guard_impl()
{
if (!m_dismissed)
m_action();
}
private:
T m_action;
};
}
template<class T>
detail::guard_impl<T> make_guard(T x)
{
return detail::guard_impl<T>(x);
}
typedef const detail::guard_base& scope_guard;
>John
>
>
>----- Original Message -----
>From: "David Abrahams" <dave_at_[hidden]>
>Newsgroups: gmane.comp.lib.boost.devel
>Sent: Wednesday, September 24, 2003 8:17 AM
>Subject: Re: ScopeGuard
>
>
> > "John Sheehan" <dumbnose_at_[hidden]> writes:
> >
> > > I took the ScopeGuard implementation by Andrei Alexandrescu and
> > > reimplemented it using Boost.Function and Boost.Bind. I was able to
> > > implement it with a single class and one helper function per supported
> > > signature. It is really useful. If anyone is interested, I can send
> > > it to them or post it to the list.
> >
> > Please post it! Would you like to submit it for review?
> >
> > --
> > Dave Abrahams
> > Boost Consulting
> > www.boost-consulting.com
> >
> > _______________________________________________
> > Unsubscribe & other changes:
>http://lists.boost.org/mailman/listinfo.cgi/boost
> >
>
>
>_______________________________________________
>Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
--- Daniel Wallin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk