std::move_only_function:: operator bool
From cppreference.net
<
cpp
|
utility
|
functional
|
move only function
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Function objects
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
explicit
operator
bool
(
)
const
noexcept
;
|
(C++23 이후) | |
* this 가 호출 가능한 대상을 저장하는지, 즉 비어 있지 않은지 확인합니다.
목차 |
매개변수
(없음)
반환값
true 만약 * this 가 호출 가능한 대상을 저장하고 있는 경우, false 그렇지 않은 경우.
예제
이 코드 실행
#include <functional> #include <iostream> void sampleFunction() { std::cout << "This is the sample function!\n"; } void checkFunc(std::move_only_function<void() const> 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::move_only_function<void() const> f1{}; std::move_only_function<void() const> 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!
참고 항목
|
(C++23)
|
std::move_only_function
을
nullptr
와 비교합니다
(함수) |
|
대상이 포함되어 있는지 확인합니다
(
std::function<R(Args...)>
의
public 멤버 함수)
|