SourceLocation comparisons

There are times I find it useful to compare two SourceLocations in the same file. I’ve noticed the operators ==, != and < are all defined for SourceLocations, but not >, >= or <=. Is there any reason these are omitted? For now I’m having to make do with using getRawEncoding() to compare them and it would make the code look cleaner to avoid this. Of course I’m assuming the encoded value always increases as you go through the file, which seems to be the case.

Thanks,
Robert Ankeney

There are times I find it useful to compare two SourceLocations in the
same file. I've noticed the operators ==, != and < are all defined for
SourceLocations, but not >, >= or <=. Is there any reason these are
omitted? For now I'm having to make do with using getRawEncoding() to
compare them

Why? You can express the other 3 with just <.

x > y <==> y < x
x >= y <==> !(x < y)
x <= y <==> !(y < x)

-- Sean Silva

While true, such constructs can reduce code readability. Why not complete the set? The cost is minimal.

Thanks again,
Robert Ankeney

I don't think that this is necessarily true due to macros. I was told that
the right way to compare them is with SourceManager::isBeforeInTranslationUnit.
Hopefully someone can provide a concrete example?

I understand the macro concern. I am only working with preprocessed code in a RecursiveASTVisitor, so a full set of comparators would make it easier for me.

Robert