]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server : use lambda instead of std::bind (#11507)
authorDaniel Bevenius <redacted>
Thu, 30 Jan 2025 10:05:00 +0000 (11:05 +0100)
committerGitHub <redacted>
Thu, 30 Jan 2025 10:05:00 +0000 (11:05 +0100)
This commit replaces the two usages of `std::bind` in favor of lambdas for
the callback functions for `callback_new_task` and
`callback_update_slots`.

The motivation for this changes is consistency with the rest of the code
in server.cpp (lambdas are used for all other callbacks/handlers). Also
lambdas are more readable (perhaps this is subjective) but also they are
recommended over `std::bind` in modern C++.

Ref: https://github.com/LithoCoders/dailycpp/blob/master/EffectiveModernC%2B%2B/chapter6/Item34_Prefer_lambdas_to_std::bind.md

examples/server/server.cpp

index 6e28d283a46e652a33ade6014395721ef42f2724..b9aa5c81c94f52ee5801d86055ceed1c43dc6e29 100644 (file)
@@ -4387,11 +4387,13 @@ int main(int argc, char ** argv) {
         ctx_server.chat_templates.template_default->source().c_str(),
         common_chat_format_example(*ctx_server.chat_templates.template_default, ctx_server.params_base.use_jinja).c_str());
 
-    ctx_server.queue_tasks.on_new_task(std::bind(
-                &server_context::process_single_task, &ctx_server, std::placeholders::_1));
+    ctx_server.queue_tasks.on_new_task([&ctx_server](const server_task & task) {
+        ctx_server.process_single_task(task);
+    });
 
-    ctx_server.queue_tasks.on_update_slots(std::bind(
-                &server_context::update_slots, &ctx_server));
+    ctx_server.queue_tasks.on_update_slots([&ctx_server]() {
+        ctx_server.update_slots();
+    });
 
     shutdown_handler = [&](int) {
         ctx_server.queue_tasks.terminate();