std::experi...urce_checked(3) C++ Standard Libary std::experi...urce_checked(3) NAME std::experimental::make_unique_resource_checked - std::experimen- tal::make_unique_resource_checked Synopsis Defined in header <experimental/scope> template< class R, class D, class S = std::decay_t<R> > std::experimental::unique_resource<std::decay_t<R>, std::decay_t<D>> (li- brary make_unique_resource_checked( R&& r, const S& invalid, D&& funda- mentals TS v3) d ) noexcept(/*see below*/); Creates a unique_resource, initializes its stored resource handle is initialized with std::forward<R>(r) and its deleter with std::forward<D>(d). The created unique_resource owns the resource if and only if bool(r == invalid) is false. The program is ill-formed if the expression r == invalid cannot be con- textually converted to bool, and the behavior is undefined if the conversion re- sults in undefined behavior or throws an exception. Exceptions Any exception thrown in initialization of the stored resource handle and the deleter. noexcept specification: noexcept( std::is_nothrow_constructible_v<std::decay_t<R>, R> && std::is_nothrow_constructible_v<std::decay_t<D>, D> ) Notes make_unique_resource_checked exists to avoid calling a deleter function with an invalid argument. Resource handle r is either copied or moved into the return value, and the created unique_resource always holds an underlying resource handle with object type. Example // Run this code #include <cstdio> #include <experimental/scope> int main() { // avoid calling fclose when fopen fails auto file = std::experimental::make_unique_resource_checked( std::fopen("potentially_nonexistent_file.txt", "r"), nullptr, [](std::FILE *fptr) { std::fclose(fptr); } ); if (file.get()) std::puts("The file exits."); else std::puts("The file does not exist."); } Possible output: The file does not exist. See also Category: * conditionally noexcept http://cppreference.com 2024.06.10 std::experi...urce_checked(3)
NAME | Synopsis | Exceptions | Notes | Example | Possible output: | See also | Category:
Want to link to this manual page? Use this URL:
<https://man.FreeBSD.org/cgi/man.cgi?query=std::experimental::make_unique_resource_checked&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>