Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::unique...operatorbool(3) C++ Standard Libarystd::unique...operatorbool(3)

NAME
       std::unique_ptr::operatorbool - std::unique_ptr::operatorbool

Synopsis
	  explicit operator bool() const noexcept;  (since C++11)
						    (constexpr since C++23)

	  Checks whether *this owns an object, i.e. whether get() != nullptr.

Parameters
	  (none)

Return value
	  true if *this	owns an	object,	false otherwise.

Example
       // Run this 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)

http://cppreference.com		  2022.07.31	 std::unique...operatorbool(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::unique_ptr::operatorbool&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help