@@ -1349,13 +1349,23 @@ if (isInputRange!Range && !isInfinite!Range &&
1349
1349
// if we only have one statement in the loop, it can be optimized a lot better
1350
1350
static if (__traits(isSame, map, a => a))
1351
1351
{
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
+ }
1353
1363
// direct access via a random access range is faster
1354
1364
static if (isRandomAccessRange! Range )
1355
1365
{
1356
1366
foreach (const i; 0 .. r.length)
1357
1367
{
1358
- if (selectorFun(r[i], extremeElement ))
1368
+ if (selectorFun(r[i], getExtremeElement ))
1359
1369
{
1360
1370
extremeElement = r[i];
1361
1371
}
@@ -1365,7 +1375,7 @@ if (isInputRange!Range && !isInfinite!Range &&
1365
1375
{
1366
1376
while (! r.empty)
1367
1377
{
1368
- if (selectorFun(r.front, extremeElement ))
1378
+ if (selectorFun(r.front, getExtremeElement ))
1369
1379
{
1370
1380
extremeElement = r.front;
1371
1381
}
@@ -3880,6 +3890,14 @@ if (isInputRange!Range && !isInfinite!Range &&
3880
3890
assert (arr.maxElement! " a.val" .val == 1 );
3881
3891
}
3882
3892
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
+
3883
3901
// minPos
3884
3902
/**
3885
3903
Computes a subrange of `range` starting at the first occurrence of `range`'s
0 commit comments