Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::apply and tuples to avoid deprecated std::bind #132

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions amtl/am-thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ static inline void SetThreadName(std::thread* thread, const char* name) {
template <class Function, class... Args>
static inline std::unique_ptr<std::thread> NewThread(const char* name, Function&& f, Args&&... args)
{
auto callback = std::bind(std::forward<Function>(f), std::forward<Args>(args)...);
auto fn = [](const std::string& name, decltype(callback)&& callback) -> void {
SetThreadName(name.c_str());
callback();
};
return std::make_unique<std::thread>(std::move(fn), std::string(name), std::move(callback));
return std::make_unique<std::thread>(
[name, fn = std::forward<Function>(f), tup = std::make_tuple(std::forward<Args>(args)...)]() mutable {
SetThreadName(name);
std::apply(std::move(fn), std::move(tup));
}
);
}

} // namespace ke
Expand Down