Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

search(), search_n()

Library: Algorithms


Function

Local Index

No Entries

Summary

An algorithm that finds a subsequence within a sequence of values

Synopsis

#include <algorithm>
namespace std {
 template <class ForwardIterator1, class ForwardIterator2>
 ForwardIterator1 search(ForwardIterator1 start1,
 ForwardIterator1 finish1,
 ForwardIterator2 start2,
 ForwardIterator2 finish2);
 template <class ForwardIterator1,
 class ForwardIterator2,
 class BinaryPredicate>
 ForwardIterator1 search(ForwardIterator1 start1,
 ForwardIterator1 finish1,
 ForwardIterator2 start2,
 ForwardIterator2 finish2,
 BinaryPredicate binary_pred);
 template <class ForwardIterator, class Size, class T>
 ForwardIterator search_n(ForwardIterator start,
 ForwardIterator finish,
 Size count, const T& value);
 template <class ForwardIterator, class Size,
 class T, class BinaryPredicate>
 ForwardIterator search_n(ForwardIterator start 
 ForwardIterator finish,
 Size count, const T& value,
 BinaryPredicate pred)
}

Description

The search() and search_n() algorithms search for a subsequence within a sequence. The search() algorithm searches for a subsequence [start2, finish2) within a sequence [start1, finish1), and returns the beginning location of the subsequence. If it does not find the subsequence, search() returns finish1. The first version of search() uses operator==() as a default, and the second version allows you to specify a binary predicate to perform the comparison.

The search_n() algorithm searches for the subsequence composed of count occurrences of value within a sequence [start, finish), and returns start if this subsequence is found. If it does not find the subsequence, search_n() returns finish. The first version of search_n() uses operator==() as a default, and the second version allows you to specify a binary predicate to perform the comparison.

Complexity

search() performs at most (finish1 - start1)*(finish2-start2) applications of the corresponding predicate.

search_n() performs at most (finish - start)* count applications of the corresponding predicate.

Example

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.1.9



Previous fileTop of DocumentContentsIndex pageNext file

AltStyle によって変換されたページ (->オリジナル) /