From a172e6cc278fe0a842cedc2b1c008d7957a1d8d7 Mon Sep 17 00:00:00 2001 From: gouzil <66515297+gouzil@users.noreply.github.com> Date: Thu, 3 Aug 2023 19:38:11 +0800 Subject: [PATCH] [clang-tidy][task 46] enable `modernize-avoid-bind` (#55895) * [clang-tidy] modernize-avoid-bind * rollback --- .clang-tidy | 2 +- paddle/fluid/framework/dist_multi_trainer.cc | 3 +-- paddle/fluid/framework/multi_trainer.cc | 3 +-- paddle/fluid/framework/op_desc.cc | 7 ++++--- paddle/fluid/framework/operator.cc | 13 +++++++------ paddle/phi/core/threadpool.cc | 3 +-- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index c13a3811f00..67b42a531cf 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -165,7 +165,7 @@ bugprone-unused-raii, -hicpp-exception-baseclass, -misc-unused-alias-decls, -misc-unused-using-decls, --modernize-avoid-bind, +modernize-avoid-bind, -modernize-avoid-c-arrays, -modernize-deprecated-headers, -modernize-deprecated-ios-base-aliases, diff --git a/paddle/fluid/framework/dist_multi_trainer.cc b/paddle/fluid/framework/dist_multi_trainer.cc index 5b93b4bcef4..3a5787a665c 100644 --- a/paddle/fluid/framework/dist_multi_trainer.cc +++ b/paddle/fluid/framework/dist_multi_trainer.cc @@ -88,8 +88,7 @@ void DistMultiTrainer::InitDumpEnv() { } } for (int i = 0; i < dump_thread_num_; i++) { - dump_thread_.push_back( - std::thread(std::bind(&TrainerBase::DumpWork, this, i))); + dump_thread_.push_back(std::thread([this, i] { DumpWork(i); })); } } diff --git a/paddle/fluid/framework/multi_trainer.cc b/paddle/fluid/framework/multi_trainer.cc index 220b11efb1b..923b8c406c0 100644 --- a/paddle/fluid/framework/multi_trainer.cc +++ b/paddle/fluid/framework/multi_trainer.cc @@ -107,8 +107,7 @@ void MultiTrainer::InitDumpEnv() { } } for (int i = 0; i < dump_thread_num_; i++) { - dump_thread_.push_back( - std::thread(std::bind(&TrainerBase::DumpWork, this, i))); + dump_thread_.push_back(std::thread([this, i] { DumpWork(i); })); } } diff --git a/paddle/fluid/framework/op_desc.cc b/paddle/fluid/framework/op_desc.cc index 69939df7619..bd0c40b3287 100644 --- a/paddle/fluid/framework/op_desc.cc +++ b/paddle/fluid/framework/op_desc.cc @@ -350,9 +350,10 @@ class CompileTimeInferShapeContext : public InferShapeContext { names.begin(), names.end(), retv.begin(), - std::bind(std::mem_fn(&CompileTimeInferShapeContext::GetVarType), - this, - std::placeholders::_1)); + std::bind( + std::mem_fn(&CompileTimeInferShapeContext::GetVarType), // NOLINT + this, + std::placeholders::_1)); return retv; } diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 1b55dea874a..e9192732124 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -710,12 +710,13 @@ std::vector RuntimeInferShapeContext::GetVarTypes( const std::vector& vars) const { std::vector retv; retv.resize(vars.size()); - std::transform(vars.begin(), - vars.end(), - retv.begin(), - std::bind(std::mem_fn(&RuntimeInferShapeContext::GetVarType), - this, - std::placeholders::_1)); + std::transform( + vars.begin(), + vars.end(), + retv.begin(), + std::bind(std::mem_fn(&RuntimeInferShapeContext::GetVarType), // NOLINT + this, + std::placeholders::_1)); return retv; } diff --git a/paddle/phi/core/threadpool.cc b/paddle/phi/core/threadpool.cc index 482f8c9bf83..d820df80e7d 100644 --- a/paddle/phi/core/threadpool.cc +++ b/paddle/phi/core/threadpool.cc @@ -55,8 +55,7 @@ ThreadPool::ThreadPool(int num_threads) : running_(true) { threads_.resize(num_threads); for (auto& thread : threads_) { // TODO(Yancey1989): binding the thread on the specify CPU numberw - thread = - std::make_unique(std::bind(&ThreadPool::TaskLoop, this)); + thread = std::make_unique([this] { ThreadPool::TaskLoop(); }); } } -- GitLab