Commit 148045d0 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Sara Golemon

Fix the example for folly::static_function_deleter.

Summary: [Folly] Fix the example for folly::static_function_deleter.

The problem is that

    int BIO_free(BIO*)

is not directly compatible.

So have two examples. One using `RSA_free` which is compatible, and one making a compatible wrapper around `BIO_free`.

Reviewed By: @Gownta

Differential Revision: D2381125
parent 3a6c9d38
......@@ -61,7 +61,17 @@ make_unique(Args&&...) = delete;
*
* So you can write this:
*
* using BIO_deleter = folly::static_function_deleter<BIO, &BIO_free>;
* 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())
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment