CBMC
freert Struct Reference

A functor wrapping std::free. More...

#include <freer.h>

Public Member Functions

template<typename T >
void operator() (T &&t) const
 

Detailed Description

A functor wrapping std::free.

Can be used as the deleter of a unique_ptr to free memory originally allocated by std::malloc. This is primarily useful for interfacing with C APIs in a memory-safe way. Note that the approach of using an empty functor as a unique_ptr deleter does not impose any space overhead on the unique_ptr instance, whereas using a function-pointer as the deleter requires the unique_ptr to store this function pointer internally, effectively doubling the size of the object. Therefore, std::unique_ptr<T, freert> should be preferred to std::unique_ptr<T, decltype(&std::free)>.

Definition at line 24 of file freer.h.

Member Function Documentation

◆ operator()()

template<typename T >
void freert::operator() ( T &&  t) const
inline

Definition at line 27 of file freer.h.


The documentation for this struct was generated from the following file: