binder1st 클래스

이진 함수의 첫 번째 인수를 지정된 값에 바인딩하여 이진 함수 개체를 단항 함수 개체로 변환하는 생성자를 제공하는 클래스 템플릿입니다. 바인딩을 위해 C++11에서 더 이상 사용되지 않으며 C++17에서 제거됩니다.

구문

template <class Operation>
class binder1st
    : public unaryFunction <typename Operation::second_argument_type,
                             typename Operation::result_type>
{
public:
    typedef typename Operation::argument_type argument_type;
    typedef typename Operation::result_type result_type;
    binder1st(
        const Operation& binary_fn,
        const typename Operation::first_argument_type& left);

    result_type operator()(const argument_type& right) const;
    result_type operator()(const argument_type& right) const;

protected:
    Operation op;
    typename Operation::first_argument_type value;
};

매개 변수

binary_fn
단항 함수 개체로 변환할 이항 함수 개체입니다.

left
이항 함수 개체의 첫 번째 인수가 바인딩되는 값입니다.

right
수정된 이진 개체를 두 번째 인수의 고정 값과 비교하는 인수의 값입니다.

Return Value

이진 함수 개체의 첫 번째 인수를 왼쪽에 바인딩한 결과인 단항 함수 개체입니다.

설명

클래스 템플릿은 binary_fn op 이진 함수 개체의 복사본과 왼쪽있는 복사본을 저장합니다value. 해당 멤버 함수 operator() 를 반환으로 정의합니다 op(value, right).

binary_fn 형식의 개체이고 c 상수 bind1st(binary_fn, c) 인 경우 보다 편리합니다binder1st<Operation>(binary_fn, c)Operation. 자세한 내용은 bind1st를 참조하세요.

예제

// functional_binder1st.cpp
// compile with: /EHsc
#include <vector>
#include <functional>
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    vector<int> v1;
    vector<int>::iterator Iter;

    int i;
    for (i = 0; i <= 5; i++)
    {
        v1.push_back(5 * i);
    }

    cout << "The vector v1 = ( ";
    for (Iter = v1.begin(); Iter != v1.end(); Iter++)
        cout << *Iter << " ";
    cout << ")" << endl;

    // Count the number of integers > 10 in the vector
    vector<int>::iterator::difference_type result1;
    result1 = count_if(v1.begin(), v1.end(),
        binder1st<less<int> >(less<int>(), 10));
    cout << "The number of elements in v1 greater than 10 is: "
         << result1 << "." << endl;

    // Compare use of binder2nd fixing 2nd argument:
    // count the number of integers < 10 in the vector
    vector<int>::iterator::difference_type result2;
    result2 = count_if(v1.begin(), v1.end(),
        binder2nd<less<int> >(less<int>(), 10));
    cout << "The number of elements in v1 less than 10 is: "
         << result2 << "." << endl;
}
The vector v1 = ( 0 5 10 15 20 25 )
The number of elements in v1 greater than 10 is: 3.
The number of elements in v1 less than 10 is: 2.