How do custom deleters affect unique_ptr and shared_ptr type, size, control blocks, and C-API integration?
Show answer and explanation
For unique_ptr, the deleter is part of the pointer's type and stored with it, so stateful deleters can change object size, move behavior, and API signatures; implementations can often compress an empty deleter but portable code should not require a specific layout. For shared_ptr, the deleter is type-erased into the ownership control block, leaving the shared_ptr type independent of the deleter. Custom deleters adapt resources such as FILE handles, sockets, or library objects to RAII, but they must accept the configured pointer type, tolerate the intended null policy, and never throw during destruction.
For unique_ptr, the deleter is part of the pointer's type and stored with it, so stateful deleters can change object size, move behavior, and API signatures; implementations can often compress an empty deleter but portable code should not require a specific layout. For shared_ptr, the deleter is type-erased into the ownership control block, leaving the shared_ptr type independent of the deleter. Custom deleters adapt resources such as FILE handles, sockets, or library objects to RAII, but they must accept the configured pointer type, tolerate the intended null policy, and never throw during destruction.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.