名前空間
変種
操作

std::search_n

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <algorithm>
template< class ForwardIt, class Size, class T >
ForwardIt1 search_n( ForwardIt first, ForwardIt last, Size count, const T& value );
(1)
template< class ForwardIt, class Size, class T, class BinaryPredicate >

ForwardIt1 search_n( ForwardIt first, ForwardIt last, Size count, const T& value,

                     BinaryPredicate p );
(2)
検索数が同一の要素、与えられた値の値に等しいそれぞれの最初のシーケンスの範囲[first, last)。最初のバージョンは、要素を比較するoperator==使用して、2番目のバージョンは、指定されたバイナリ述語pを使用しています.
Original:
Searches the range [first, last) for the first sequence of count identical elements, each equal to the given value value. The first version uses operator== to compare the elements, the second version uses the given binary predicate p.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

first, last -
検討する要素の範囲
Original:
the range of elements to examine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count -
を検索するためのシーケンスの長さ
Original:
the length of the sequence to search for
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
value -
検索する要素の値
Original:
the value of the elements to search for
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - binary predicate which returns ​true if the elements should be treated as equal.

The signature of the predicate function should be equivalent to the following:

 bool pred(const Type1 &a, const Type2 &b);

The signature does not need to have const &, but the function must not modify the objects passed to it.
The type  Type1 must be such that an object of type ForwardIt can be dereferenced and then implicitly converted to  Type1. The type  Type2 must be such that an object of type T can be implicitly converted to  Type2.

Type requirements
-
ForwardIt must meet the requirements of ForwardIterator.

[編集] 値を返します

レンジ[first, last)に見出される配列の先頭にIiterator。そのようなシーケンスが見つからない場合は、lastが返されます.
Original:
Iiterator to the beginning of the found sequence in the range [first, last). If no such sequence is found, last is returned.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 複雑

述部の中で最もlast - firstアプリケーションで.
Original:
At most last - first applications of the predicate.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 可能な実装

First version
template<class ForwardIt, class Size, class T>
ForwardIt1 search_n(ForwardIt first, ForwardIt last,
                          Size count, const T& value)
{
    Size curr_count = 0;
    ForwardIt result, t_last = first;
    std::advance(t_last, std::distance(first, last) - count + 1);
 
    for (; first != t_last; first++) {
        curr_count = 0;
        result = first;
        while (*first == value) {
            curr_count++;
            if (curr_count == count) {
                return result;
            }
            ++first;
        }
    }
    return last;
}
Second version
template<class ForwardIt, class Size, class T, class BinaryPredicate>
ForwardIt1 search_n(ForwardIt first, ForwardIt last,
                          Size count, const T& value, BinaryPredicate p)
{
    Size curr_count = 0;
    ForwardIt result, t_last = first;
    std::advance(t_last, std::distance(first, last) - count + 1);
 
    for (; first != t_last; first++) {
        curr_count = 0;
        result = first;
        while (p(*first == value)) {
            curr_count++;
            if (curr_count == count) {
                return result;
            }
            ++first;
        }
    }
    return last;
}

[編集]

[編集] も参照してください

一定の範囲内にある要素の最後のシーケンスを見つけることができます
Original:
finds the last sequence of elements in a certain range
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
特定の条件を満たす最初の要素を検索します
Original:
finds the first element satisfying specific criteria
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
searches for a range of elements
(関数テンプレート) [edit]