functional_is_bind_expression

functional_is_bind_expression (바인드 표현식 판별 특성)

이 페이지는 C++ 표준 라이브러리의 std::is_bind_expression 특성(trait)에 대해 설명해요. 이 특성은 주어진 타입이 std::bind에 의해 생성된 바인드 표현식인지 여부를 컴파일 타임에 판별하는 데 사용돼요. 사용자 정의 타입에 대해 이 특성을 특수화하여 std::bind가 해당 타입을 바인드 하위 표현식으로 취급하도록 지정할 수도 있어요.

출처: cppreference

본문

정의

<functional> 헤더에 정의됨
template < class T > struct is_bind_expression ; (C++11부터)

설명

만약 Tstd::bind 호출로 생성된 타입이라면(std::bind_frontstd::bind_back은 제외), 이 템플릿은 std::true_type에서 파생돼요. 다른 모든 타입(사용자 특수화가 없는 경우)에 대해서는 std::false_type에서 파생돼요.

프로그램은 프로그램 정의 타입 T에 대해 이 템플릿을 특수화하여 std::true_type의 기본 특성으로 UnaryTypeTrait를 구현할 수 있어요. 이는 Tstd::bind에 의해 바인드 하위 표현식의 타입인 것처럼 취급되어야 함을 나타내요. 바인드로 생성된 함수 객체가 호출될 때, 이 타입의 바인드 인자는 함수 객체로 호출되며, 바인드로 생성된 객체에 전달된 모든 비바인드 인자를 받게 돼요.

헬퍼 변수 템플릿

template < class T > constexpr bool is_bind_expression_v = is_bind_expression < T >:: value ; (C++17부터)

std::integral_constant로부터 상속

멤버 상수

value [static] Tstd::bind로 생성된 함수 객체이면 true, 그렇지 않으면 false (공용 정적 멤버 상수)

멤버 함수

operator bool 객체를 bool로 변환하고 value를 반환해요 (공용 멤버 함수)
operator() (C++14) value를 반환해요 (공용 멤버 함수)

멤버 타입

타입 정의
value_type bool
type std::integral_constant < bool, value >

예제

#include <functional>
#include <iostream>
#include <type_traits>

struct MyBind
{
    typedef int result_type;
    int operator()(int a, int b) const { return a + b; }
};

namespace std
{
    template<>
    struct is_bind_expression<MyBind> : public true_type {};
}

int f(int n1, int n2)
{
    return n1 + n2;
}

int main()
{
    // as if bind(f, bind(MyBind(), _1, _2), 2)
    auto b = std::bind(f, MyBind(), 2); 
    
    std::cout << "Adding 2 to the sum of 10 and 11 gives " << b(10, 11) << '\n';
}

출력:

Adding 2 to the sum of 10 and 11 gives 23

결함 보고서

다음 동작 변경 결함 보고서는 이전에 발표된 C++ 표준에 소급 적용되었어요.

DR 적용 대상 발표된 동작 올바른 동작
LWG 2010 C++11 프로그램 정의 특수화는 std::false_type에서만 파생될 수 있었음 std::true_type에서 파생될 수 있음

같이 보기

bind (C++11) 하나 이상의 인자를 함수 객체에 바인드해요 (함수 템플릿) [edit]

더 알아보기 (Learn more)

cppreference