digitalmars.D.learn - Implementing swap for user-defined swaps
- Balagopal Komarath (12/12) Oct 07 2017 Hello,
- ag0aep6g (3/13) Oct 07 2017 You can't provide your own swap function. `sort` etc. use
Hello, I was implement my own range type that forwards all accesses to another range. I tried to write a `swap` function so that sort etc. could be called on my range. However, I cannot get `hasSwappableElements!ARange` to evaluate to true. But, when I copy pasted the definition of `hasSwappableElements` into my module and evaluated it, it was true. I assume this is something to do with how name lookup works in D. Here's simplified code that reproduces the same problem. https://dpaste.dzfl.pl/48a420cce261 Thanks, Balagopal.
Oct 07 2017
On 10/07/2017 07:55 PM, Balagopal Komarath wrote:I was implement my own range type that forwards all accesses to another range. I tried to write a `swap` function so that sort etc. could be called on my range. However, I cannot get `hasSwappableElements!ARange` to evaluate to true. But, when I copy pasted the definition of `hasSwappableElements` into my module and evaluated it, it was true. I assume this is something to do with how name lookup works in D. Here's simplified code that reproduces the same problem. https://dpaste.dzfl.pl/48a420cce261You can't provide your own swap function. `sort` etc. use std.algorithm.swap, so your range has to work with that.
Oct 07 2017