Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Реализация класса scoped_resource настолько проста и элегантна, что даже чем-то напомнила мне идею Y-combinator'a.Так где код-то?
try
{
int fd = ::open("file", ...);
// i don't wrap it no more time
throw exception();
}
catch(exception&)
{
// oh no
}
FILE* f = fopen("file", "rb");
if(!f) throw FileException();
finally([&f] { fclose(f); });
// reading file... BeginUpdate();
finally([this] { EndUpdate(); });
// updating...sqlite3* db;
sqlite3_open("some.db", &db);
scope(exit) sqlite3_close(db);ha::scoped_resource<int, char*, int> fd(::open, filename.c_str(), O_RDONLY, ::close);scoped_ptr<int> fd(::open(filename.c_str(), O_RDONLY), [](int fd_) { ::close(fd_); });
RAII + С++ variadic templates = win