37 ms·
Oh, so then on C++ you can check if pointer-to-T p is within T a[sz]; by doing (a == p || std::less(a, p)) && (std::less(p, a + sz))
by tehrei 10y ago
Oh, so then on C++ you can check if pointer-to-T p is within T a[sz]; by doing (a == p || std::less(a, p)) && (std::less(p, a + sz))
- gpderetta 10y agoPossibly not. The standard guarantees that less yields a total order for pointers. But the ordering itself is unspecified, and not even guaranteed to be consistent with operator< for pointers to elements of the same array.
- yoklov 10y agoI thought it was UB to use < on pointers outside of the same block of memory. e.g. your function is fine if the answer is true, but UB if the answer is false. I could be misremembering though, but I do know I'd always cast to uintptr_t for this.