Re: Further C++ operators for position
Hans Åberg <[email protected]>
| Newsgroups | gmane.comp.parsers.bison.general |
|---|---|
| Message-ID | <[email protected]> |
> On 4 Nov 2019, at 07:52, Akim Demaille <[email protected]> wrote: > >> Le 4 nov. 2019 à 05:27, Matthew Fernandez <[email protected]> a écrit : >> >> I recently had a use case for comparing source positions coming out of a C++ Bison-produced parser. While operator== and operator!= are implemented on the position class [0], the ordering operators (<, <=, >, >=) are not. It was relatively straightforward to implement these myself, but I was wondering if these were of wider use and should live upstream in Bison’s position implementation. Perhaps there is some history behind this or some deliberate omission of these operators? Just wanted to ask if there’s a reason these don’t already exist before thinking about posting a patch. I’m not subscribed to the list, so please CC me in replies. > > The semantics for line and columns are quite clear, so comparing Positions in the same file is quite well defined. > > But what should you do when the files are different? (And Locations are intervals, so there's no way to compare them totally in a natural order.) > > What we can do, though, is offer implementations for std::less, that would blindly apply the lexicographic order in both cases. > > But the case of file names remains troublesome: should we compare the pointer addresses (super fast, but non deterministic) or the pointees (super slow, but deterministic)? As it is not semantically well defined, but that one might want a total order for use in types like std::map, a pointer comparison might be used. Also containers like std::unordered_set have a total order through the iterators, so it fits with C++ paradigms, I would think.