Skip to content

Commit abd708a

Browse files
committed
Fix variant usage for macOS < 10.14
macOS does not support std::bad_variant_access until 10.14, and some package managers target macos < 10.14, so we need to avoid parts of std::variant which might raise such exceptions
1 parent ee68c89 commit abd708a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cxx/isce3/geometry/TopoLayers.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "TopoLayers.h"
22

33
#include <iterator>
4+
#include <stdexcept>
45
#include <variant>
56
#include <vector>
67

@@ -19,11 +20,17 @@ void TopoLayers::writeData(size_t xidx, size_t yidx)
1920
#pragma omp parallel for
2021
for (auto i = 0; i < valarrays.size(); ++i) {
2122
if (rasters[i]) {
22-
std::visit(
23-
[&](const auto& ptr) {
24-
rasters[i]->setBlock(ptr, xidx, yidx, _width, _length);
25-
},
26-
valarrays[i]);
23+
24+
// std::bad_variant_access requires macOS 10.14
25+
if (auto* p = std::get_if<double*>(&valarrays[i])) {
26+
rasters[i]->setBlock(*p, xidx, yidx, _width, _length);
27+
} else if (auto* p = std::get_if<float*>(&valarrays[i])) {
28+
rasters[i]->setBlock(*p, xidx, yidx, _width, _length);
29+
} else if (auto* p = std::get_if<short*>(&valarrays[i])) {
30+
rasters[i]->setBlock(*p, xidx, yidx, _width, _length);
31+
} else {
32+
throw std::logic_error("invalid variant type");
33+
}
2734
}
2835
}
2936
}

0 commit comments

Comments
 (0)