Operator overloading for size_t

Alec Stewart alec-stewart at protonmail.com
Thu Mar 14 18:07:46 UTC 2019


I thought (for shits and giggles) to try and implement the 
Aho-Corasick algorithm[1].


I thought I'd start with a struct to represent the "interval":

     struct Interval {
         size_t d_start;
         size_t d_end;
         size_t size;

         this(size_t start, size_t end) {
             d_start = start;
             d_end = end;
             size = d_end - d_start + 1;
         }
     }

It'd be useful to check for equality and inequality between 
instances of `Interval`, so I thought to use `.opEquals` for 
`d_start` and `d_end`.

     bool opEquals(ref const Interval i) const {
         // probably would be a bit more than just this, but for 
this issue
         // let's just stick with this.
         return d_start.opEquals(other.d_start) && 
d_end.opEquals(other.d_end);
     }


But I do get an error saying

`none of the overloads  of `opEquals` are callable using argument 
types `(const(ulong), const(ulong))`, candidates are:` and it 
doesn't say the candidates.

So should I bother with operator overloading here, or just make a 
member function?

[1] https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm


More information about the Digitalmars-d-learn mailing list