View source code
							
							
						
								Display the source code in std/algorithm/searching.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Function std.algorithm.searching.maxElement
Iterates the passed range and returns the maximal element.
A custom mapping function can be passed to map.
In other languages this is sometimes called argmax.
						
				auto auto maxElement(alias map, Range)
				(
				
				  Range r
				
				)
				
				if (isInputRange!Range && !isInfinite!Range);
				
				
				auto auto maxElement(alias map, Range, RangeElementType)
				(
				
				  Range r,
				
				  RangeElementType seed
				
				)
				
				if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void));
						
					
				Complexity
Exactly n - 1 comparisons are needed.
Parameters
| Name | Description | 
|---|---|
| map | custom accessor for the comparison key | 
| r | range from which the maximum will be selected | 
| seed | custom seed to use as initial element | 
Returns
The maximal element of the passed-in range.
See Also
Example
import stdAuthors
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.