C++ Logo

STD-DISCUSSION

Advanced search

Subject: Portable check for aliasing / contiguous range overlap
From: Schneider, Robert (robert.schneider03_at_[hidden])
Date: 2020-02-18 10:49:00


Hi, is there a portable and efficient way to check if two contiguous ranges overlap, e.g. span<tuple<double, array<int, 3>>> st = ...; span<int> si = ...; if(overlap(st, si)) // careful, slower algorithm which deals with overlap else // fast algorithm I think the guarantees of expr.rel are insufficient, even std::less doesn't seem to provide the necessary guarantees. Raymond Chen proposed casting the pointers to integers and relying on guarantees of the implementation. It would also be possible to write something like: for(byte const& bt : as_bytes(st)) for(byte const& bi : as_bytes(si)) if(&bt == &bi) return true; return false; But this is rather slow in debug builds without optimizations. Is there maybe a better way? Thanks, Robert


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups