stdpain commented on a change in pull request #5706: URL: https://github.com/apache/incubator-doris/pull/5706#discussion_r619971972
########## File path: be/src/util/defer_op.h ########## @@ -34,6 +34,24 @@ class DeferOp { DeferFunction _func; }; +// A Better Defer operator #5576 +// for C++17 +// Defer defer {[]{ call something }}; +// +// for C++11 +// auto op = [] {}; +// Defer<decltype<op>> (op); +template <class T> +class Defer { +public: + Defer(T& closure) : _closure(closure) {} Review comment: std::forward<T>(closure) will got a compile error such as: ``` error: cannot bind rvalue reference of type 'main()::<lambda()>&&' to lvalue of type 'main()::<lambda()>' ``` ########## File path: be/src/util/file_utils.cpp ########## @@ -240,16 +240,15 @@ Status FileUtils::copy_file(const std::string& src_path, const std::string& dest } const int64_t BUF_SIZE = 8192; - char* buf = new char[BUF_SIZE]; - DeferOp free_buf(std::bind<void>(std::default_delete<char[]>(), buf)); + std::unique_ptr<char[]> buf(new char[BUF_SIZE]); Review comment: fixed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org