Skip to content

Commit

Permalink
use std::visit to replace std::get_if.
Browse files Browse the repository at this point in the history
Signed-off-by: light-city <[email protected]>

fix tidy
  • Loading branch information
Light-City committed Aug 26, 2024
1 parent 05091d7 commit 1950ec4
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions include/knowhere/dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,21 @@ class DataSet : public std::enable_shared_from_this<const DataSet> {
return;
}
for (auto&& x : this->data_) {
{
auto ptr = std::get_if<0>(&x.second);
if (ptr != nullptr) {
delete[] * ptr;
}
}
{
auto ptr = std::get_if<1>(&x.second);
if (ptr != nullptr) {
delete[] * ptr;
}
}
{
auto ptr = std::get_if<2>(&x.second);
if (ptr != nullptr) {
delete[] * ptr;
}
}
{
auto ptr = std::get_if<3>(&x.second);
if (ptr != nullptr) {
if (is_sparse) {
delete[](sparse::SparseRow<float>*)(*ptr);
} else {
delete[](char*)(*ptr);
std::visit(
[](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, const float*> || std::is_same_v<T, const size_t*> ||
std::is_same_v<T, const int64_t*>) {
if (arg != nullptr) {
delete[] arg;
}
} else if constexpr (std::is_same_v<T, const void*>) {
if (arg != nullptr) {
delete[](char*)(arg);
}
}
}
}
},
x.second);
}
}

Expand Down

0 comments on commit 1950ec4

Please sign in to comment.