|
// Boost dependent version of SCOPE_EXIT.
#pragma once
#include <functional>
#include <boost/noncopyable.hpp>
#include <boost/preprocessor.hpp>
class scope_exit_t : private boost::noncopyable
{
typedef std::function<void()> func_t;
public:
scope_exit_t(func_t &&f) : func(f) {}
~scope_exit_t() { func(); }
private:
// Prohibit construction from lvalues.
scope_exit_t(func_t &);
// Prohibit new/delete.
void *operator new(size_t);
void *operator new[](size_t);
void operator delete(void *);
void operator delete[](void *);
const func_t func;
};
#define SCOPE_EXIT scope_exit_t BOOST_PP_CAT(scope_exit_, __COUNTER__) = [&]
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
In 1985, I got my first computer Casio MX-10, the cheapest one of
MSX home computers. Then I began programming in BASIC and assembly language, and have experienced over ten languages from that time on.
Now, my primary languages are C++ and C#. Working for a small company in my home town in a rural area of Japan.