linksplatform / Ranges

LinksPlatform's Platform.Ranges Class Library
https://linksplatform.github.io/Ranges
The Unlicense
4 stars 1 forks source link

Can we use here templates? #44

Closed poul250 closed 3 years ago

poul250 commented 3 years ago

https://github.com/linksplatform/Ranges/blob/d7b5ac881f7e8921520f5264ce04a1d97dfd31c3/cpp/Platform.Ranges/RangeExtensions.h#L5-L23

do that like this:

template<typename T>
public: static T Difference(Range<T> range) { return range.Maximum - range.Minimum; }

Return type is T, but we can also use auto.

uselessgoddess commented 3 years ago

In the C++20 standard we can use

template<typename T> requires 
    requires(T maximum, T minimum) { maximum - minimum; }
public: static T Difference(Range<T> range) { return range.Maximum - range.Minimum; }

For all types with operator- or builtin '-'

Konard commented 3 years ago

Yes, we can. Looks like this issue was solved by #61