Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74735

c++ compare if 2 span points to the same memory

$
0
0

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 = {};
    }
}

Viewing all articles
Browse latest Browse all 74735

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>