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 = (lastfirst) 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

Name

Description

first

Iterator to the first element of the range to search.

last

Iterator one past the last element of the range to search.

value

The value to search for.

Created with MrDocs