absl::linear_search

Performs a linear search for a value in a range.

Synopsis

Declared in <absl/algorithm/algorithm.h>

template<
    typename InputIterator,
    typename EqualityComparable>
constexpr
bool
linear_search(
    InputIterator first,
    InputIterator last,
    EqualityComparable const& value);

Description

Searches the range [first, last)] and returns true if it contains an element equal to value.

A linear search is of O(n) complexity and makes at most n = (last - first) comparisons. A linear search over short containers may be faster than a binary search, even when the container is sorted.

Return Value

true if [first, last)] contains an element equal to value.

Parameters

NameDescription
firstIterator to the first element of the range to search.
lastIterator one past the last element of the range to search.
valueThe value to search for.