Namespaces
Variants

std::function<R(Args...)>::operator bool

cppreference.net에서
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐기됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교환타입 연산
(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까지*)
 
 
explicit operator bool() const noexcept;
(C++11부터)

*this가 호출 가능 함수 대상을 저장하고 있는지, 즉 비어 있지 않은지 확인합니다.

매개변수

(없음)

반환값

true 만약 * this 가 호출 가능한 함수 타겟을 저장하고 있는 경우, false 그렇지 않은 경우.

예제

#include <functional>
#include <iostream>
void sampleFunction()
{
    std::cout << "This is the sample function!\n";
}
void checkFunc(std::function<void()> const& func)
{
    // operator bool을 사용하여 호출 가능한 대상이 있는지 확인합니다.
    if (func)  
    {
        std::cout << "Function is not empty! Calling function.\n";
        func();
    }
    else
        std::cout << "Function is empty. Nothing to do.\n";
}
int main()
{
    std::function<void()> f1;
    std::function<void()> f2(sampleFunction);
    std::cout << "f1: ";
    checkFunc(f1);
    std::cout << "f2: ";
    checkFunc(f2);
}

출력:

f1: Function is empty. Nothing to do.
f2: Function is not empty! Calling function.
This is the sample function!

참고 항목

std::move_only_function 이 대상을 가지고 있는지 확인합니다
( std::move_only_function 의 public member function)