I realise that according to the C++ standard it isn't legal to compare two pointers which are not from the same array. Is anyone aware of anything in g++ which would actually forbid this, and if there is any way of checking if will be valid?
I want to be able to perform two main operations. Firstly to compare any pair of pointers with ==, and also to write code like: template<typename T> bool in_range(T* begin, T* end, T* value) { return (begin <= value) != (end <= value); } Where value may be a pointer not from the same array as begin and end. Apologises for sending this question to the main gcc list, but I want to submit such code to the debugging part of libstdc++-v3, and wanted to check if any optimisations may make use the fact comparing pointers from different arrays is undefined. Thank you, Chris