std::functi...operatorbool(3)
π NAME π
okay so welcome to the std::functi...operatorbool(3) page from the C++ Standard Libary (yes, that's the header's spelling π), aka the C++ Standard Library. This is std::function::operatorbool β and yep, that's the whole name again: std::function::operatorbool. It's the vibe check operator for whether your std::function is holding a callable function target or is just sitting there empty like an unread group chat π.
β¨ Synopsis β¨
explicit operator bool() const noexcept; (since C++11)
Checks whether *this stores a callable function target, i.e. is not empty. That's the whole vibe check, bestie: callable target present = not empty; no callable target = empty. Periodt.
π Parameters π
(none) β literally none, bestie. Not a single parameter. This operator needs zero help π
.
π Return value π
true if *this stores a callable function target, false otherwise. No cap, that's it.
π Example π
// Run this code β yes, actually run it, it's cute. Here's the whole demo:
#include <functional>
#include <iostream>
void sampleFunction()
{
std::cout << "This is the sample function!\n";
}
void checkFunc(std::function<void()> const& func)
{
// Use operator bool to determine if callable target is available.
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);
}
π Output: π
f1: Function is empty. Nothing to do.
f2: Function is not empty! Calling function.
This is the sample function!
π¦ See also π¦
operator boolchecks if thestd::move_only_functionhas a target (C++23) β public member function ofstd::move_only_function.
Source/version/date check: this page is from http://cppreference.com, dated 2024.06.10, and filed as std::functi...operatorbool(3). Bye bestie, go give your callables a vibe check π«Άβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms