[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Further C++ operators for position
From: |
Hans Åberg |
Subject: |
Re: Further C++ operators for position |
Date: |
Mon, 4 Nov 2019 18:46:00 +0100 |
> On 4 Nov 2019, at 07:52, Akim Demaille <address@hidden> wrote:
>
>> Le 4 nov. 2019 à 05:27, Matthew Fernandez <address@hidden> 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.
- Re: Further C++ operators for position, (continued)
- Re: Further C++ operators for position, Christian Schoenebeck, 2019/11/04
- Re: Further C++ operators for position, Matthew Fernandez, 2019/11/04
- Re: Further C++ operators for position, Akim Demaille, 2019/11/04
- Re: Further C++ operators for position, Hans Åberg, 2019/11/04
- Re: Further C++ operators for position, Matthew Fernandez, 2019/11/04
- Re: Further C++ operators for position, Akim Demaille, 2019/11/05
- Re: Further C++ operators for position, Matthew Fernandez, 2019/11/05
- Re: Further C++ operators for position, Akim Demaille, 2019/11/05
- Re: Further C++ operators for position, Akim Demaille, 2019/11/05
- Re: Further C++ operators for position, Hans Åberg, 2019/11/05
Re: Further C++ operators for position,
Hans Åberg <=