C++ Logo


Advanced search

Portable check for aliasing / contiguous range overlap

From: Schneider, Robert <robert.schneider03_at_[hidden]>
Date: Tue, 18 Feb 2020 16:49:00 +0000
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

Received on 2020-02-18 10:51:47