Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move struct Steps inside steps(), add @property

  • Loading branch information...
commit 1510d3f4c9d02c74fbd1f21adc757155f9503c8b 1 parent a862fde
@kyllingstad kyllingstad authored
Showing with 26 additions and 32 deletions.
  1. +26 −32 scid/util.d
View
58 scid/util.d
@@ -270,46 +270,40 @@ unittest
}
---
*/
-Steps!(CommonType!(T, U)) steps(T, U)(T a, U b, int n)
+auto steps(T, U)(T a, U b, int n)
if (isFloatingPoint!T && isFloatingPoint!U)
{
- return typeof(return)(a, b, n);
-}
-
-
-struct Steps(T) if (isFloatingPoint!T)
-{
-private:
- int _i, _resolution;
- T _delta, _start, _stop;
-
-public:
- this(T start, T stop, int resolution)
- in { assert (resolution >= 0); }
- body {
- _start = start;
- _stop = stop;
- if (resolution > 1) _delta = (stop - start) / (resolution - 1);
- _i = resolution - 1;
- _resolution = resolution;
- }
+ alias CommonType!(T, U) V;
+ struct Steps
+ {
+ private:
+ int _i, _resolution;
+ V _delta, _start, _stop;
- bool empty() { return _i < 0; }
+ public:
+ @property bool empty() { return _i < 0; }
+ @property V front()
+ {
+ assert (!empty);
+ if (_i == _resolution - 1) return _start;
+ return _stop - _i*_delta;
+ }
- T front()
- {
- assert (!empty);
- if (_i == _resolution - 1) return _start;
- return _stop - _i*_delta;
+ void popFront() {
+ assert (!empty);
+ --_i;
+ }
}
-
- void popFront() {
- assert (!empty);
- --_i;
- }
+ Steps s;
+ s._start = a;
+ s._stop = b;
+ if (n > 1) s._delta = (b - a) / (n - 1);
+ s._i = n - 1;
+ s._resolution = n;
+ return s;
}
Please sign in to comment.
Something went wrong with that request. Please try again.