名前空間
変種
操作

std::find, std::find_if, std::find_if_not

提供: 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.
find
find_if
find_if_not


(C++11)
find_end
find_first_of
adjacent_find
search
search_n
シーケンス動作を変更する
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 InputIt, class T >
InputIt find( InputIt first, InputIt last, const T& value );
(1)
template< class InputIt, class UnaryPredicate >

InputIt find_if( InputIt first, InputIt last,

                 UnaryPredicate p );
(2)
template< class InputIt, class UnaryPredicate >

InputIt find_if_not( InputIt first, InputIt last,

                     UnaryPredicate q );
(3) (C++11およびそれ以降)
これらの関数は、特定の基準を満たす範囲[first, last)内の最初の要素を見つけます
Original:
These functions find the first element in the range [first, last) that satisfies specific criteria:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1。 findに等しい要素のvalue検索します
Original:
1. find searches for an element equal to value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2。 find_if要素を検索しているの述語p戻りtrue
Original:
2. find_if searches for an element for which predicate p returns true
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3。 find_if_not要素を検索している述語のq戻りfalse
Original:
3. find_if_not searches for element for which predicate q returns false
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.
value -
に要素を比較する値
Original:
value to compare the elements to
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - unary predicate which returns ​true
必須要素のために
Original:
for the required element
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

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

 bool pred(const Type &a);

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

q - unary predicate which returns ​false
必須要素のために
Original:
for the required element
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

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

 bool pred(const Type &a);

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

Type requirements
-
InputIt must meet the requirements of InputIterator.

[編集] 値を返します

このような要素が見つからない場合の条件またはlastを満たす最初の要素へのイテレータ.
Original:
Iterator to the first element satisfying the condition or last if no such element is found.
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 InputIt, class T>
InputIt find(InputIt first, InputIt last, const T& value)
{
    for (; first != last; ++first) {
        if (*first == value) {
            return first;
        }
    }
    return last;
}
Second version
template<class InputIt, class UnaryPredicate>
InputIt find_if(InputIt first, InputIt last, UnaryPredicate p)
{
    for (; first != last; ++first) {
        if (p(*first)) {
            return first;
        }
    }
    return last;
}
Third version
template<class InputIt, class UnaryPredicate>
InputIt find_if_not(InputIt first, InputIt last, UnaryPredicate q)
{
    for (; first != last; ++first) {
        if (!q(*first)) {
            return first;
        }
    }
    return last;
}
あなたが持っていない場合は、C + +11、std::find_if_notに相当するものは否定述語とstd::find_ifを使用することです.
Original:
If you do not have C++11, an equivalent to std::find_if_not is to use std::find_if with the negated predicate.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
template<class InputIt, class UnaryPredicate>
InputIt find_if_not(InputIt first, InputIt last, UnaryPredicate q)
{
    return std::find_if(first, last, std::not1(q));
}

[編集]

次の例では、整数のベクトルでの整数を求め.
Original:
The following example finds an integer in a vector of integers.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <algorithm>
#include <vector>
 
int main()
{
    int n1 = 3;
    int n2 = 5;
 
    std::vector<int> v{0, 1, 2, 3, 4};
 
    auto result1 = std::find(v.begin(), v.end(), n1);
    auto result2 = std::find(v.begin(), v.end(), n2);
 
    if (result1 != v.end()) {
        std::cout << "v contains: " << n1 << '\n';
    } else {
        std::cout << "v does not contain: " << n1 << '\n';
    }
 
    if (result2 != v.end()) {
        std::cout << "v contains: " << n2 << '\n';
    } else {
        std::cout << "v does not contain: " << n2 << '\n';
    }
}

Output:

v contains: 3
v does not contain: 5

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

互いに隣接する2つの同一の(またはいくつかの他の関係)のアイテムを見つけることができます
Original:
finds two identical (or some other relationship) items adjacent to each other
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 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]
searches for any one of a set of elements
(関数テンプレート) [edit]
2の範囲が異なる最初の位置を見つけます
Original:
finds the first position where two ranges differ
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]