注意:这篇文章上次更新于1497天前,文章内容可能已经过时。
This article was last updated1497 days ago, the content may be outdated.
分享一个在公司看到的头文件。
Share a header file seen at the company.
1 |
|
使用方法:
- 如果你想写一个删除掉拷贝构造函数和拷贝赋值函数的类,那么你可以继承 disable_copying_and_assignment
Usage:
- If you want to write a class that deletes the copy constructor and the copy assignment operator, you can inherit from
disable_copying_and_assignment
1 | class myclass : public disable_copying_and_assignment |
- smart_lambda 有点类似于 lock_guard ,在离开作用域时执行函数。一个可能的使用场景是当你的函数中存在许多分支,但是return之前必须做一件相同的事,使用 smart_lambda 可以避免代码的重复。
smart_lambdais somewhat similar tolock_guard— it executes the function when leaving the scope. One possible use case is when your function has many branches but must do the same thing before everyreturn; usingsmart_lambdaavoids code duplication.
1 | void function(int index) |
这样无论从哪个分支结束,都会输出函数执行结束了。
smart_both_lambda 和 smart_condition_lambda 的功能也显而易见。
This way, no matter which branch the function returns from, it will always print that the function has finished executing.
smart_both_lambda and smart_condition_lambda are self-explanatory as well.


