@@ -1349,13 +1349,23 @@ if (isInputRange!Range && !isInfinite!Range &&
13491349 // if we only have one statement in the loop, it can be optimized a lot better
13501350 static if (__traits(isSame, map, a => a))
13511351 {
1352-
1352+ CommonElement getExtremeElement ()
1353+ {
1354+ static if (is (typeof (extremeElement) == T[], T))
1355+ {
1356+ return extremeElement;
1357+ }
1358+ else
1359+ {
1360+ return extremeElement.get ;
1361+ }
1362+ }
13531363 // direct access via a random access range is faster
13541364 static if (isRandomAccessRange! Range )
13551365 {
13561366 foreach (const i; 0 .. r.length)
13571367 {
1358- if (selectorFun(r[i], extremeElement ))
1368+ if (selectorFun(r[i], getExtremeElement ))
13591369 {
13601370 extremeElement = r[i];
13611371 }
@@ -1365,7 +1375,7 @@ if (isInputRange!Range && !isInfinite!Range &&
13651375 {
13661376 while (! r.empty)
13671377 {
1368- if (selectorFun(r.front, extremeElement ))
1378+ if (selectorFun(r.front, getExtremeElement ))
13691379 {
13701380 extremeElement = r.front;
13711381 }
@@ -3880,6 +3890,14 @@ if (isInputRange!Range && !isInfinite!Range &&
38803890 assert (arr.maxElement! " a.val" .val == 1 );
38813891}
38823892
3893+ // https://issues.dlang.org/show_bug.cgi?id=23993
3894+ @safe unittest
3895+ {
3896+ import std.bigint : BigInt;
3897+
3898+ assert ([BigInt(2 ), BigInt(3 )].maxElement == BigInt(3 ));
3899+ }
3900+
38833901// minPos
38843902/**
38853903Computes a subrange of `range` starting at the first occurrence of `range`'s
0 commit comments