digitalmars.D.learn - Testing for object property supporting "<" comparison
- Chris Piker (27/27) May 11 2021 Hi D
- Paul Backus (3/9) May 11 2021 std.traits.isOrderingComparable
- Chris Piker (3/6) May 11 2021 Well I feel sheepish, don't know how I missed that one. Hey
Hi D I'm working on a bit of code that handles selecting one *.front from multiple range-ish objects. It's a select-or-drop algorithm for a data streaming service, the details aren't important. The algorithm takes a range of something I'll call "PriorityRange" objects. PriorityRange objects are like input ranges, but have a few extra members. The set is: .empty : Returns bool .front : Returns something non-void .popFront(): Return void .priority : Returns something comparable via "<" to other .priority values for all input PriortyRanges .min : Returns something comparable to .max below via "<" for all input PriorityRanges .max : Returns something comparable to .min above via "<" for all input PriorityRanges I noticed the isInputRange(R) enum from std/range/primitives.d and am wondering how to setup a similar check, call it "isPriorityRange(PR)". My problem is that I don't know how to specify that properties must be comparable via "<". I took a look at the Traits module, but there are more things that are comparable then Arithmetic or Floating point types. Also, since the compiler will catch objects that don't have these properties, maybe an enum check is not worth implementing. Thanks very much for any advice you might have, Cheers
May 11 2021
On Tuesday, 11 May 2021 at 19:42:34 UTC, Chris Piker wrote:My problem is that I don't know how to specify that properties must be comparable via "<". I took a look at the Traits module, but there are more things that are comparable then Arithmetic or Floating point types. Also, since the compiler will catch objects that don't have these properties, maybe an enum check is not worth implementing.std.traits.isOrderingComparable https://phobos.dpldocs.info/std.traits.isOrderingComparable.html
May 11 2021
On Wednesday, 12 May 2021 at 00:06:52 UTC, Paul Backus wrote:On Tuesday, 11 May 2021 at 19:42:34 UTC, Chris Piker wrote: std.traits.isOrderingComparable https://phobos.dpldocs.info/std.traits.isOrderingComparable.htmlWell I feel sheepish, don't know how I missed that one. Hey thanks for pointing it out.
May 11 2021