`touches` is poorly specified

Aperta
#62 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@jofaber ci sta già lavorando.

Dal 13/11/2026.

  • #67 di @jofaber — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Start with include/boost/icl/concept/interval.hpp at the touches implementation linked in the issue, then compare its behavior with the documented function reference and the two reproductions. Decide and implement consistent behavior for reversed argument order and empty intervals, updating documentation and tests to define the expected cases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The implementation of touches:

https://github.com/boostorg/icl/blob/b587925c05ab626436822a5d5e3317a5da97f320/include/boost/icl/concept/interval.hpp#L1007-L1034

assumes that left is to the left of right, yet this precondition is not documented:

touches(x,y) Between the disjoint intervals x and y are no elements.

So, we end up with touches not being symmetric (https://godbolt.org/z/7zPoe6hYj):

#include <boost/icl/interval.hpp>
#include <iostream>

int main()
{
  boost::icl::closed_interval<int> x(0, 1), y(2, 3);

  std::cout << touches(x, y) << "\n"; // outputs 1
  std::cout << touches(y, x) << "\n"; // outputs 0
}

Additionally, empty intervals are handled in a way that is inconsistent with interval equality (https://godbolt.org/z/dxjGbsYr8):

#include <boost/icl/interval.hpp>
#include <iostream>

int main()
{
  boost::icl::right_open_interval<int> empty0(0, 0), empty1(5, 5), y(0, 1);

  std::cout << (empty0 == empty1) << "\n"; // outputs 1
  std::cout << touches(empty0, y) << "\n"; // outputs 1
  std::cout << touches(empty1, y) << "\n"; // outputs 0
}

In the example empty0 and empty1 are equal, yet one touches y and the other does not, thus breaking the generally assumed equality preservation property.

My suggestions for improvement are:

  • Document the precondition that x must precede y in touches(x, y) or else make touches behave symmetrically (touches(x, y) == touches(y, x) whenever touches(x, y) is well defined).
  • Clarify what "x touches y" means when one or both of x, y are empty, or else explicitly disqualify passing empty intervals to touches.
  • If empty intervals are allowed, make the implementation of touches equality-preserving when an empty interval is replaced by another empty interval.
Lingua principale
C++
Stelle
15
Fork
51
Merge medio
8g 6h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di boostorg/icl

Tutte le issue di boostorg/icl

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.