From c8a784f0cad915f98f6a4f965f677ffec2134405 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 22 Feb 2018 23:34:09 +0300 Subject: [PATCH] CxCli: better TryRemove. GitOrigin-RevId: ef4394f1dd2d1fdf6609412ec666954316aafa66 --- tdutils/td/utils/port/CxCli.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tdutils/td/utils/port/CxCli.h b/tdutils/td/utils/port/CxCli.h index bac7a8b0f..778f5cabc 100644 --- a/tdutils/td/utils/port/CxCli.h +++ b/tdutils/td/utils/port/CxCli.h @@ -49,9 +49,15 @@ public: value = it->second; return true; } - void TryRemove(Key key, Value &value) { + bool TryRemove(Key key, Value &value) { std::lock_guard guard(mutex_); - impl_.erase(key); + auto it = impl_.find(key); + if (it == impl_.end()) { + return false; + } + value = std::move(it->second); + impl_.erase(it); + return true; } Value &operator [] (Key key) { std::lock_guard guard(mutex_);