Repository: xbmc/xbmc
File: xbmc/utils/Variant.cpp (C++)

Code before:
    m_data = VariantArray{};
  }

  if (type() == VariantTypeArray)
    std::get<VariantArray>(m_data).emplace_back(std::move(variant));
}

void CVariant::append(const CVariant &variant)
{
  push_back(variant);
}

void CVariant::append(CVariant&& variant)
{
  push_back(std::move(variant));
}

const char *CVariant::c_str() const
{
  return std::visit(overloaded{[](const std::string& s) { return s.c_str(); },
                               [](const auto&) -> const char* { return nullptr; }},
                    m_data);
}

void CVariant::swap(CVariant& rhs) noexcept
{
  std::swap(m_data, rhs.m_data);
}

CVariant::iterator_array CVariant::begin_array()
{
  return std::visit(overloaded{[](VariantArray& a) { return a.begin(); },
                               [](auto&) { return EMPTY_ARRAY.begin(); }},
                    m_data);
}

CVariant::const_iterator_array CVariant::begin_array() const
{
  return std::visit(overloaded{[](const VariantArray& a) { return a.cbegin(); },
                               [](const auto&) { return EMPTY_ARRAY.cbegin(); }},
                    m_data);
}

CVariant::iterator_array CVariant::end_array()
{
  return std::visit(
      overloaded{[](VariantArray& a) { return a.end(); }, [](auto&) { return EMPTY_ARRAY.end(); }},
      m_data);
}

CVariant::const_iterator_array CVariant::end_array() const

Review comment (suggestion):
[nitpick] The swap implementation forces rhs to become a ConstNull variant when the current variant is ConstNull, which deviates from symmetric swapping. If this behavior is intentional, please add an inline comment to clarify this special case.
```suggestion
{
  // If the current variant is ConstNull, force rhs to become ConstNull as well.
  // This deviates from symmetric swapping but might be intentional for handling special cases.
```

Code after:
    m_data = VariantArray{};
  }

  if (type() == VariantTypeArray)
    std::get<VariantArray>(m_data).emplace_back(std::move(variant));
}

void CVariant::append(const CVariant &variant)
{
  push_back(variant);
}

void CVariant::append(CVariant&& variant)
{
  push_back(std::move(variant));
}

const char *CVariant::c_str() const
{
  return std::visit(overloaded{[](const std::string& s) { return s.c_str(); },
                               [](const auto&) -> const char* { return nullptr; }},
                    m_data);
}

void CVariant::swap(CVariant& rhs) noexcept
{
  if (type() == VariantTypeConstNull)
    rhs = VariantTypeConstNull;
  else
    std::swap(m_data, rhs.m_data);
}

CVariant::iterator_array CVariant::begin_array()
{
  return std::visit(overloaded{[](VariantArray& a) { return a.begin(); },
                               [](auto&) { return EMPTY_ARRAY.begin(); }},
                    m_data);
}

CVariant::const_iterator_array CVariant::begin_array() const
{
  return std::visit(overloaded{[](const VariantArray& a) { return a.cbegin(); },
                               [](const auto&) { return EMPTY_ARRAY.cbegin(); }},
                    m_data);
}

CVariant::iterator_array CVariant::end_array()
{
  return std::visit(
      overloaded{[](VariantArray& a) { return a.end(); }, [](auto&) { return EMPTY_ARRAY.end(); }},
      m_data);