1 /** 2 Reverses the range by mutating it 3 */ 4 module ddash.algorithm.reverse; 5 6 /// 7 unittest { 8 auto arr = [1, 2, 3, 4]; 9 arr.reverse; 10 assert(arr.equal([4, 3, 2, 1])); 11 } 12 13 import ddash.common; 14 15 /** 16 Reverses elements in a range 17 18 Params: 19 range = the range to reverse 20 21 Since: 22 0.0.1 23 */ 24 void reverse(Range)(ref Range range) 25 if (from!"std.range".isBidirectionalRange!Range 26 && !from!"std.range".isRandomAccessRange!Range 27 && from!"std.range".hasSwappableElements!Range 28 || (from!"std.range".isRandomAccessRange!Range && from!"std.range".hasLength!Range)) 29 { 30 import std.algorithm: reverse; 31 range.reverse; 32 }