_1 개체
대체 가능한 인수 자리 표시자
namespace placeholders {
extern unspecified _1, _2, ... _M
} // namespace placeholders (within std)
설명
개체 _1, _2, ... _M은 함수 호출에서 각각 첫 번째, 두 번째, ..., M번째 인수를 bind 함수가 반환한 개체에 지정하는 자리 표시자입니다. 바인딩 식을 계산하는 경우 _N을 사용하여 N번째 인수가 삽입될 위치를 지정할 수 있습니다.
이 구현에서 M의 값은 20입니다.
예제
// std__functional_placeholder.cpp
// compile with: /EHsc
#include <functional>
#include <algorithm>
#include <iostream>
using namespace std::placeholders;
void square(double x)
{
std::cout << x << "^2 == " << x * x << std::endl;
}
void product(double x, double y)
{
std::cout << x << "*" << y << " == " << x * y << std::endl;
}
int main()
{
double arg[] = {1, 2, 3};
std::for_each(&arg[0], &arg[3], square);
std::cout << std::endl;
std::for_each(&arg[0], &arg[3], std::bind(product, _1, 2));
std::cout << std::endl;
std::for_each(&arg[0], &arg[3], std::bind(square, _1));
return (0);
}
요구 사항
헤더: <기능>
네임스페이스: std