proxygen
folly::static_function_deleter< T, f > Struct Template Reference

#include <Memory.h>

Public Member Functions

void operator() (T *t) const
 

Detailed Description

template<typename T, void(*)(T *) f>
struct folly::static_function_deleter< T, f >

static_function_deleter

So you can write this:

 using RSA_deleter = folly::static_function_deleter<RSA, &RSA_free>;
 auto rsa = std::unique_ptr<RSA, RSA_deleter>(RSA_new());
 RSA_generate_key_ex(rsa.get(), bits, exponent, nullptr);
 rsa = nullptr;  // calls RSA_free(rsa.get())

This would be sweet as well for BIO, but unfortunately BIO_free has signature int(BIO*) while we require signature void(BIO*). So you would need to make a wrapper for it:

 inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); }
 using BIO_deleter = folly::static_function_deleter<BIO, &BIO_free_fb>;
 auto buf = std::unique_ptr<BIO, BIO_deleter>(BIO_new(BIO_s_mem()));
 buf = nullptr;  // calls BIO_free(buf.get())

Definition at line 298 of file Memory.h.

Member Function Documentation

template<typename T , void(*)(T *) f>
void folly::static_function_deleter< T, f >::operator() ( T t) const
inline

Definition at line 299 of file Memory.h.

References f.

299  {
300  f(t);
301  }
auto f

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