Extract a value of type T from a DataVariant at a specific position.
514{
515 return std::visit([pos](const auto& data) -> std::optional<T> {
516 using DataType = std::decay_t<decltype(data)>;
517 using ValueType = typename DataType::value_type;
518
519 if (pos >= data.size()) {
520 return std::nullopt;
521 }
522
523 if constexpr (std::is_same_v<ValueType, T>) {
524 return data[pos];
525 } else if constexpr (std::is_arithmetic_v<ValueType> && std::is_arithmetic_v<T>) {
526 return static_cast<T>(data[pos]);
527 } else if constexpr (std::is_same_v<ValueType, std::complex<float>> || std::is_same_v<ValueType, std::complex<double>>) {
528 if constexpr (std::is_arithmetic_v<T>) {
529 return static_cast<T>(std::abs(data[pos]));
530 } else {
531 return std::nullopt;
532 }
533 } else {
534 return std::nullopt;
535 }
536 },
537 variant);
538}