From cd402cab4777f9570d22addd915c9ad5dd127b80 Mon Sep 17 00:00:00 2001 From: Grigory Nikolaenko Date: Sun, 24 Jun 2018 00:00:03 +0300 Subject: [PATCH] Fixed more lambda warnings throughout the sources. --- blocks/http/test.cc | 2 +- blocks/http/types.h | 4 +- bricks/graph/gnuplot.h | 4 +- bricks/sync/test.cc | 2 +- karl/karl.h | 187 ++++++++++++++-------------- karl/test_service/http_subscriber.h | 2 +- nlp/nlp.h | 10 +- 7 files changed, 101 insertions(+), 110 deletions(-) diff --git a/blocks/http/test.cc b/blocks/http/test.cc index 1c8d34335..07e363764 100644 --- a/blocks/http/test.cc +++ b/blocks/http/test.cc @@ -1615,7 +1615,7 @@ TEST(HTTPAPI, ResponseSmokeTest) { }) + HTTP(FLAGS_net_api_test_port) .Register("/response10", - [send_response](Request r) { + [](Request r) { SerializableVariant v; v.template Construct(); r(v); diff --git a/blocks/http/types.h b/blocks/http/types.h index 2ed6b4487..4b9608f66 100644 --- a/blocks/http/types.h +++ b/blocks/http/types.h @@ -122,9 +122,7 @@ template struct FillBody { template static typename std::enable_if)>::type Fill( - REQUEST& request, - T&& object, - const std::string& content_type) { + REQUEST& request, T&& object, const std::string& content_type) { request.body = JSON(std::forward(object)); request.content_type = !content_type.empty() ? content_type : net::constants::kDefaultJSONContentType; } diff --git a/bricks/graph/gnuplot.h b/bricks/graph/gnuplot.h index 32a5fbc3d..b85ecfd69 100644 --- a/bricks/graph/gnuplot.h +++ b/bricks/graph/gnuplot.h @@ -235,8 +235,8 @@ struct GNUPlot { } } if (output_format_ != "gnuplot") { - CURRENT_ASSERT(!bricks::system::SystemCall(current::strings::Printf( - strings::Printf("gnuplot <%s >%s", input_file_name.c_str(), output_file_name.c_str()).c_str()))); + CURRENT_ASSERT(!bricks::system::SystemCall( + strings::Printf("gnuplot <%s >%s", input_file_name.c_str(), output_file_name.c_str()))); return current::FileSystem::ReadFileAsString(output_file_name.c_str()); } else { // For unit tests, just compare the inputs. diff --git a/bricks/sync/test.cc b/bricks/sync/test.cc index 2771ba69e..56ae09bc2 100644 --- a/bricks/sync/test.cc +++ b/bricks/sync/test.cc @@ -181,7 +181,7 @@ TEST(OwnedBorrowed, BorrowedWithCallbackOutlivingTheOwner) { std::atomic_bool terminating(false); // The `unique_ptr` ugliness is to have the pre-initialized `current::BorrowedWithCallback` movable. thread = std::make_unique( - [&log, &terminating](std::unique_ptr> y0) { + [&terminating](std::unique_ptr> y0) { current::BorrowedWithCallback& y = *y0.get(); EXPECT_TRUE(static_cast(y)); // Keep incrementing until external termination request. diff --git a/karl/karl.h b/karl/karl.h index e23b1363a..2df75e086 100644 --- a/karl/karl.h +++ b/karl/karl.h @@ -336,7 +336,7 @@ class GenericKarl final : private KarlStorage, public: ~GenericKarl() { destructing_ = true; - storage_->ReadWriteTransaction([this](MutableFields fields) { + storage_->ReadWriteTransaction([](MutableFields fields) { KarlInfo self_info; self_info.up = false; fields.karl.Add(self_info); @@ -547,105 +547,100 @@ class GenericKarl final : private KarlStorage, } auto& notifiable_ref = notifiable_ref_; - storage_->ReadWriteTransaction( - [this, - now, - location, - &parsed_status, - &detailed_parsed_status, - optional_behind_this_by, - ¬ifiable_ref](MutableFields fields) -> Response { - // OK to call from within a transaction. - // The call is fast, and `storage_`'s transaction guarantees thread safety. -- D.K. - notifiable_ref.OnKeepalive(now, location, parsed_status.codename, detailed_parsed_status); - - const auto& service = parsed_status.service; - const auto& codename = parsed_status.codename; - const auto& optional_build = parsed_status.build; - const auto& optional_instance = parsed_status.cloud_instance_name; - const auto& optional_av_group = parsed_status.cloud_availability_group; - - // Update per-server information in the `DB`. - ServerInfo server; - server.ip = location.ip; - bool need_to_update_server_info = false; - const ImmutableOptional current_server_info = fields.servers[location.ip]; - if (Exists(current_server_info)) { - server = Value(current_server_info); - } - // Check the instance name. - if (Exists(optional_instance)) { - if (!Exists(server.cloud_instance_name) || - Value(server.cloud_instance_name) != Value(optional_instance)) { - server.cloud_instance_name = Value(optional_instance); - need_to_update_server_info = true; - } - } - // Check the availability group. - if (Exists(optional_av_group)) { - if (!Exists(server.cloud_availability_group) || - Value(server.cloud_availability_group) != Value(optional_av_group)) { - server.cloud_availability_group = Value(optional_av_group); - need_to_update_server_info = true; - } - } - // Check the time skew. - if (Exists(optional_behind_this_by)) { - const std::chrono::microseconds behind_this_by = Value(optional_behind_this_by); - const auto time_skew_difference = server.behind_this_by - behind_this_by; - if (static_cast(std::abs(time_skew_difference.count())) >= - kUpdateServerInfoThresholdByTimeSkewDifference) { - server.behind_this_by = behind_this_by; - need_to_update_server_info = true; - } - } - if (need_to_update_server_info) { - fields.servers.Add(server); - } + storage_ + ->ReadWriteTransaction( + [now, location, &parsed_status, &detailed_parsed_status, optional_behind_this_by, ¬ifiable_ref]( + MutableFields fields) -> Response { + // OK to call from within a transaction. + // The call is fast, and `storage_`'s transaction guarantees thread safety. -- D.K. + notifiable_ref.OnKeepalive(now, location, parsed_status.codename, detailed_parsed_status); + + const auto& service = parsed_status.service; + const auto& codename = parsed_status.codename; + const auto& optional_build = parsed_status.build; + const auto& optional_instance = parsed_status.cloud_instance_name; + const auto& optional_av_group = parsed_status.cloud_availability_group; + + // Update per-server information in the `DB`. + ServerInfo server; + server.ip = location.ip; + bool need_to_update_server_info = false; + const ImmutableOptional current_server_info = fields.servers[location.ip]; + if (Exists(current_server_info)) { + server = Value(current_server_info); + } + // Check the instance name. + if (Exists(optional_instance)) { + if (!Exists(server.cloud_instance_name) || + Value(server.cloud_instance_name) != Value(optional_instance)) { + server.cloud_instance_name = Value(optional_instance); + need_to_update_server_info = true; + } + } + // Check the availability group. + if (Exists(optional_av_group)) { + if (!Exists(server.cloud_availability_group) || + Value(server.cloud_availability_group) != Value(optional_av_group)) { + server.cloud_availability_group = Value(optional_av_group); + need_to_update_server_info = true; + } + } + // Check the time skew. + if (Exists(optional_behind_this_by)) { + const std::chrono::microseconds behind_this_by = Value(optional_behind_this_by); + const auto time_skew_difference = server.behind_this_by - behind_this_by; + if (static_cast(std::abs(time_skew_difference.count())) >= + kUpdateServerInfoThresholdByTimeSkewDifference) { + server.behind_this_by = behind_this_by; + need_to_update_server_info = true; + } + } + if (need_to_update_server_info) { + fields.servers.Add(server); + } - // Update the `DB` if the build information was not stored there yet. - const ImmutableOptional current_claire_build_info = fields.builds[codename]; - if (Exists(optional_build) && - (!Exists(current_claire_build_info) || - Value(current_claire_build_info).build != Value(optional_build))) { - ClaireBuildInfo build; - build.codename = codename; - build.build = Value(optional_build); - fields.builds.Add(build); - } + // Update the `DB` if the build information was not stored there yet. + const ImmutableOptional current_claire_build_info = fields.builds[codename]; + if (Exists(optional_build) && (!Exists(current_claire_build_info) || + Value(current_claire_build_info).build != Value(optional_build))) { + ClaireBuildInfo build; + build.codename = codename; + build.build = Value(optional_build); + fields.builds.Add(build); + } - // Update the `DB` if "codename", "location", or "dependencies" differ. - const ImmutableOptional current_claire_info = fields.claires[codename]; - if ([&]() { - if (!Exists(current_claire_info)) { - return true; - } else if (Value(current_claire_info).location != location) { - return true; - } else if (Value(current_claire_info).registered_state != - ClaireRegisteredState::Active) { - return true; - } else { - return false; - } - }()) { - ClaireInfo claire; - if (Exists(current_claire_info)) { - // Do not overwrite `build` with `null`. - claire = Value(current_claire_info); + // Update the `DB` if "codename", "location", or "dependencies" differ. + const ImmutableOptional current_claire_info = fields.claires[codename]; + if ([&]() { + if (!Exists(current_claire_info)) { + return true; + } else if (Value(current_claire_info).location != location) { + return true; + } else if (Value(current_claire_info).registered_state != ClaireRegisteredState::Active) { + return true; + } else { + return false; } + }()) { + ClaireInfo claire; + if (Exists(current_claire_info)) { + // Do not overwrite `build` with `null`. + claire = Value(current_claire_info); + } - claire.codename = codename; - claire.service = service; - claire.location = location; - claire.reported_timestamp = now; - claire.url_status_page_direct = location.StatusPageURL(); - claire.registered_state = ClaireRegisteredState::Active; + claire.codename = codename; + claire.service = service; + claire.location = location; + claire.reported_timestamp = now; + claire.url_status_page_direct = location.StatusPageURL(); + claire.registered_state = ClaireRegisteredState::Active; - fields.claires.Add(claire); - } - return Response("OK\n"); - }, - std::move(r)).Wait(); + fields.claires.Add(claire); + } + return Response("OK\n"); + }, + std::move(r)) + .Wait(); { std::lock_guard lock(services_keepalive_cache_mutex_); auto& placeholder = services_keepalive_time_cache_[parsed_status.codename]; @@ -704,7 +699,7 @@ class GenericKarl final : private KarlStorage, void ServeBuild(Request r) { const auto codename = r.url_path_args[0]; - storage_->ReadOnlyTransaction([this, codename](ImmutableFields fields) -> Response { + storage_->ReadOnlyTransaction([codename](ImmutableFields fields) -> Response { const auto result = fields.builds[codename]; if (Exists(result)) { return Value(result); diff --git a/karl/test_service/http_subscriber.h b/karl/test_service/http_subscriber.h index b5dde8ee1..118f22732 100644 --- a/karl/test_service/http_subscriber.h +++ b/karl/test_service/http_subscriber.h @@ -66,7 +66,7 @@ class HTTPStreamSubscriber { HTTP(ChunkedGET(url, [this](const std::string& header, const std::string& value) { OnHeader(header, value); }, [this](const std::string& chunk_body) { OnChunk(chunk_body); }, - [this]() {})); + []() {})); } catch (current::net::NetworkException& e) { std::cerr << e.DetailedDescription() << std::endl; CURRENT_ASSERT(false); diff --git a/nlp/nlp.h b/nlp/nlp.h index 510424883..0ac8354c3 100644 --- a/nlp/nlp.h +++ b/nlp/nlp.h @@ -146,10 +146,8 @@ struct OrImplWithVariant { size_t begin, size_t end, std::function emit) const { - lhs_impl_.EvalImpl( - query, begin, end, [&query, begin, end, &emit](const LHS_TYPE& value) { emit(emitted_t(value)); }); - rhs_impl_.EvalImpl( - query, begin, end, [&query, begin, end, &emit](const RHS_TYPE& value) { emit(emitted_t(value)); }); + lhs_impl_.EvalImpl(query, begin, end, [&emit](const LHS_TYPE& value) { emit(emitted_t(value)); }); + rhs_impl_.EvalImpl(query, begin, end, [&emit](const RHS_TYPE& value) { emit(emitted_t(value)); }); } }; @@ -165,8 +163,8 @@ struct OrImplSameType { size_t begin, size_t end, std::function emit) const { - lhs_impl_.EvalImpl(query, begin, end, [&query, begin, end, &emit](const TYPE& value) { emit(emitted_t(value)); }); - rhs_impl_.EvalImpl(query, begin, end, [&query, begin, end, &emit](const TYPE& value) { emit(emitted_t(value)); }); + lhs_impl_.EvalImpl(query, begin, end, [&emit](const TYPE& value) { emit(emitted_t(value)); }); + rhs_impl_.EvalImpl(query, begin, end, [&emit](const TYPE& value) { emit(emitted_t(value)); }); } };