Namespaces
Variants

std::placeholders::_1, std::placeholders::_2, ..., std::placeholders::_N

cppreference.net에서 가져옴
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐지됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
Swap 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
함수 객체
함수 호출
(C++17)(C++23)
항등 함수 객체
(C++20)
투명 연산자 래퍼
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

이전의 바인더와 어댑터
(C++17까지*)
(C++17까지*)
(C++17까지*)
(C++17까지*)  
(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
(C++17까지*)(C++17까지*)
(C++17까지*)(C++17까지*)

(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
 
헤더 <functional>
/* see below */ _1;
/* see below */ _2;
.
.
/* see below */ _N;

에서 정의됨std::placeholders 네임스페이스에는 플레이스홀더 객체 [_1, ..., _N]가 포함되어 있으며, 여기서 N는 구현에서 정의된 최대 개수입니다.

이들이 std::bind 표현식의 인수로 사용될 때, 플레이스홀더 객체는 생성된 함수 객체에 저장되며, 해당 함수 객체가 바인드되지 않은 인수로 호출되면 각 플레이스홀더 _N는 해당하는 N번째 바인드되지 않은 인수로 대체됩니다.

각 플레이스홀더는 extern /* unspecified */ _1;에 의해 선언된 것처럼 선언됩니다.

(C++17까지)

구현은 플레이스홀더를 inline constexpr /* unspecified */ _1;에 의해 선언된 것처럼 선언하는 것이 권장되지만, extern /* unspecified */ _1;에 의해 선언하는 것도 표준에서 여전히 허용됩니다.

(C++17부터)

플레이스홀더 객체의 타입은 DefaultConstructible 및 CopyConstructible이며, 기본 복사/이동 생성자는 예외를 던지지 않으며, 임의의 플레이스홀더 _N에 대해 타입 std::is_placeholder<decltype(_N)>이 정의되며, 여기서 std::is_placeholder<decltype(_N)>는 std::integral_constant<int, N>에서 파생됩니다.

예제

다음 코드는 플레이스홀더 인수를 사용한 함수 객체 생성 방법을 보여줍니다.

#include <functional>
#include <iostream>
#include <string>
void goodbye(const std::string& s)
{
    std::cout << "Goodbye " << s << '\n';
}
class Object
{
public:
    void hello(const std::string& s)
    {
        std::cout << "Hello " << s << '\n';
    }
};
int main()
{
    using namespace std::placeholders;
    using ExampleFunction = std::function<void(const std::string&)>;
    Object instance;
    std::string str("World");
    ExampleFunction f = std::bind(&Object::hello, &instance, _1);
    f(str); // equivalent to instance.hello(str)
    f = std::bind(&goodbye, std::placeholders::_1);
    f(str); // equivalent to goodbye(str)
    auto lambda = [](std::string pre, char o, int rep, std::string post)
    {
        std::cout << pre;
        while (rep-- > 0)
            std::cout << o;
        std::cout << post << '\n';
    };
    // binding the lambda:
    std::function<void(std::string, char, int, std::string)> g =
        std::bind(&decltype(lambda)::operator(), &lambda, _1, _2, _3, _4);
    g("G", 'o', 'o'-'g', "gol");
}

출력:

Hello World
Goodbye World
Goooooooogol

참고 항목

(C++11)
하나 이상의 인수를 함수 객체에 바인딩합니다
(함수 템플릿)
객체가 표준 플레이스홀더이거나 플레이스홀더로 사용될 수 있음을 나타냅니다
(클래스 템플릿)
(C++11)
tie 를 사용하여 tuple 을 언패킹할 때 요소를 건너뛰기 위한 플레이스홀더
(상수)