Skip to content

Commit bc10764

Browse files
authored
refactor: prevent extra move for get-methods with nrvo (#73)
* removed extra move with using nrvo * fix build issue
1 parent b5e9e99 commit bc10764

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

include/thread_pool/thread_safe_queue.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace dp {
5656
std::scoped_lock lock(mutex_);
5757
if (data_.empty()) return std::nullopt;
5858

59-
auto front = std::move(data_.front());
59+
std::optional<T> front = std::move(data_.front());
6060
data_.pop_front();
6161
return front;
6262
}
@@ -65,7 +65,7 @@ namespace dp {
6565
std::scoped_lock lock(mutex_);
6666
if (data_.empty()) return std::nullopt;
6767

68-
auto back = std::move(data_.back());
68+
std::optional<T> back = std::move(data_.back());
6969
data_.pop_back();
7070
return back;
7171
}
@@ -74,7 +74,7 @@ namespace dp {
7474
std::scoped_lock lock(mutex_);
7575
if (data_.empty()) return std::nullopt;
7676

77-
auto back = std::move(data_.back());
77+
std::optional<T> back = std::move(data_.back());
7878
data_.pop_back();
7979
return back;
8080
}
@@ -95,10 +95,10 @@ namespace dp {
9595

9696
if (data_.empty()) return std::nullopt;
9797

98-
auto front = data_.front();
98+
std::optional<T> front = data_.front();
9999
data_.pop_front();
100100

101-
data_.push_back(front);
101+
data_.push_back(*front);
102102

103103
return front;
104104
}

0 commit comments

Comments
 (0)