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