kornel
June 13, 2015, 7:53pm
1
There are constants like std::u32::MAX
, but AFAIK there’s no generic way to get the maximum.
I was writing an algorithm that works on Ord
, but I needed a special value that is higher than all other values. I’ve had to roll my own trait for this, but It’d be nice to have that in stdlib.
llogiq
June 13, 2015, 8:17pm
2
Why did you need that value? Were you calculating some minimum and needed a default?
kornel
June 13, 2015, 10:11pm
3
Yes, exactly. I’m creating and searching a binary tree, and I need special values for the leaves and a starting point when searching it.
I know I could theoretically avoid having a placeholder maximum, but having it makes the code simpler.
joliv
June 13, 2015, 11:31pm
4
2 Likes
llogiq
June 14, 2015, 6:55am
5
I’d also like to refer you to the min()
(also max()
) method that is implemented for Iterator<T> where T: Ord
.
kornel
June 14, 2015, 8:53am
6
llogiq
June 14, 2015, 8:58am
7
No problem. I agree that traits sometimes makr for suboptimal discoverability. Searching for min
immediately brought me there, luckily.
Searching in the "std" docs apparently doesn't bring up results for other crates...
system
Closed
March 25, 2019, 8:24am
9
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.