std::unique...operatorbool(3)
π NAME π
okay bestie, this is the NAME section and it's giving main character energy: std::unique_ptr::operatorbool β yes, std::unique_ptr::operatorbool. That's the name, twice, because the manual said so and we respect the manual. π«Ά
This page is std::unique...operatorbool(3) from the C++ Standard Libary manual. (Yes, that's the spelling in the header β we're keeping it exactly, no edits, no cap. π
)
β¨ Synopsis β¨
explicit operator bool() const noexcept; (since C++11)
(constexpr since C++23)
So it's explicit, it's noexcept, it's been here since C++11, and it's constexpr since C++23. glow-up confirmed β¨
It checks whether *this owns an object, i.e. whether get() != nullptr. That's the whole vibe check. π
π«Ά Parameters π«Ά
(none) β literally no parameters. She takes nothing. Zero drama. π
β Return value β
true if *this owns an object, false otherwise. simple, clean, iconic. Periodt. π
π Example π
The page says // Run this code, so here's the exact code:
#include <iostream>
#include <memory>
int main()
{
std::unique_ptr<int> ptr(new int(42));
if (ptr)
std::cout << "before reset, ptr is: " << *ptr << '\n';
ptr.reset();
ptr ? (std::cout << "after reset, ptr is: " << *ptr)
: (std::cout << "after reset ptr is empty") << '\n';
}
π Output: π
before reset, ptr is: 42
after reset ptr is empty
π See also π
getβ returns a pointer to the managed object (public member function). iykyk. π¦
That's the whole page, bestie π«Ά source: http://cppreference.com, version/date: 2024.06.10, manual page: std::unique...operatorbool(3). Now go forth and check those pointers πβ¨
π¦ 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