Use std::ignore to fix unused variable warnings

This commit is contained in:
mutouyun 2024-05-19 18:49:50 +08:00
parent 9f44298350
commit a401d3f874
2 changed files with 11 additions and 9 deletions

View File

@ -3,6 +3,7 @@
#include <future>
#include <atomic>
#include <vector>
#include <tuple>
#include "benchmark/benchmark.h"
@ -18,18 +19,18 @@ void concur_queue_rtt(benchmark::State &state) {
for (std::int64_t i = 0; !stop.load(std::memory_order_relaxed); ++i) {
std::int64_t n {};
while (!que[0].pop(n)) ;
(void)que[1].push(i);
std::ignore = que[1].push(i);
}
});
for (auto _ : state) {
(void)que[0].push(0);
std::ignore = que[0].push(0);
std::int64_t n {};
while (!que[1].pop(n)) ;
}
stop = true;
(void)que[0].push(0);
std::ignore = que[0].push(0);
producer.wait();
}
@ -39,7 +40,7 @@ void concur_queue_1v1(benchmark::State &state) {
std::atomic_bool stop = false;
auto producer = std::async(std::launch::async, [&stop, &que] {
for (std::int64_t i = 0; !stop.load(std::memory_order_relaxed); ++i) {
(void)que.push(i);
std::ignore = que.push(i);
std::this_thread::yield();
}
});
@ -65,7 +66,7 @@ void concur_queue_NvN(benchmark::State &state) {
prods.resize(state.threads());
auto producer = [] {
for (std::int64_t i = 0; run.load(std::memory_order_relaxed) > 0; ++i) {
(void)que.push(i);
std::ignore = que.push(i);
std::this_thread::yield();
}
};

View File

@ -8,6 +8,7 @@
#include <atomic>
#include <array>
#include <tuple>
#include <cstddef>
#include <cstdint>
@ -46,11 +47,11 @@ private:
typename decltype(elements)::size_type i = 0;
LIBIMP_TRY {
for (; i < elements.size(); ++i) {
(void)::LIBIMP::construct<element<value_type>>(&elements[i]);
std::ignore = ::LIBIMP::construct<element<value_type>>(&elements[i]);
}
} LIBIMP_CATCH(...) {
for (decltype(i) k = 0; k < i; ++k) {
(void)::LIBIMP::destroy<element<value_type>>(&elements[k]);
std::ignore = ::LIBIMP::destroy<element<value_type>>(&elements[k]);
}
throw;
}
@ -58,7 +59,7 @@ private:
~data() noexcept {
for (auto &elem : this->elements()) {
(void)::LIBIMP::destroy<element<value_type>>(&elem);
std::ignore = ::LIBIMP::destroy<element<value_type>>(&elem);
}
}
@ -124,7 +125,7 @@ public:
~data_model() noexcept {
if (valid()) {
auto sz = data_->byte_size();
(void)::LIBIMP::destroy<data>(data_);
std::ignore = ::LIBIMP::destroy<data>(data_);
data_allocator_.deallocate(data_, sz);
}
}