Lightning Talk: FINALLY - The Presentation You've All Been Waiting For - Louis Thomas - CppCon 2021

preview_player
Показать описание
---
Lightning Talk: FINALLY - The Presentation You've All Been Waiting For - Louis Thomas - CppCon 2021

---
Louis Thomas

---

Рекомендации по теме
Комментарии
Автор

Finally, the length of video I can watch without loosing my concentration

Tmality
Автор

template <typename ActTy> struct Finally {
ActTy act;
explicit Finally(ActTy action): act(std::move(action)){}
~Finally() { act(); }
};

int main() {
int x = 0;
Finally close{[&] {std::cout << x << std::endl;}};
x = 42;
} // prints out 42

This will work in C++20 without wrapping function because of CTAD.

kostikvl
Автор

Member functions defined inside a class are already inline. The factory function also has missing template arguments (pre C++17 it won't work). GSL implementations already have improved version of this.

Xeverous
Автор

FINALLY! The presentation I’ve been waiting for!

apenasmeucanal
Автор

This is more a "defer" than a "finally"

RichardNatal
Автор

0:40, this was 1 of the reasons why I left C. I used to write a "f() destructor" back then, either via macro or goto.

MrAbrazildo
Автор

Looks like a great solution to the a problem that would best be solved by not having it in the first place ;) - why not check the assertion in the resource managers destructor or similarly print the footnote when it’s or the responsible objects time comes? why not use the c++ iostream file objects instead of the legacy C api? and finally - would you really want to write at the beginning of the function what will happen at the end?

rnr
Автор

Defer implemented as a library feature in cpp instead of language woah

rahem