public static int BinarySearch <T, TComparer>( this ReadOnlySpan <T> span, T value, TComparer comparer) where TComparer : IComparer <T> { if (comparer == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer); } var comparable = new SpanHelpers.ComparerComparable <T, TComparer>( value, comparer); return(BinarySearch(span, comparable)); }
public static int BinarySearch <T, TComparer>( this ReadOnlySpan <T> span, T value, TComparer comparer) where TComparer : IComparer <T> { if (comparer == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer); } // TODO: Do we accept a null comparer and then revert to T as IComparable if possible?? // T:System.ArgumentException: // comparer is null, and value is of a type that is not compatible with the elements // of array. // T:System.InvalidOperationException: // comparer is null, and T does not implement the System.IComparable`1 generic interface var comparable = new SpanHelpers.ComparerComparable <T, TComparer>( value, comparer); return(BinarySearch(span, comparable)); }