I need to compare from std::span, but only if they point to the same memory. Is this solution safe ? The code works well compiled with gcc-9.2.0
template <typename T>
auto sameMemory(const T* first, const T* second) noexcept -> bool
{
return static_cast<const void*>(first) == static_cast<const void*>(second);
}
void function(gsl::span<uint8_t> memoryView) noexcept
{
auto& span { _spans[_index] };
if (sameMemory(span.data(), memoryView.data())) {
...Do something with memoryView
span = {};
}
}