Skip to content

Commit

Permalink
docs: update guidance for binding functions
Browse files Browse the repository at this point in the history
Tweaked the docs to call out equivalent STL functions and their
relationship with std::shared_ptr.

A rendered version can be found here:
https://github.com/andrwng/kudu/blob/docs_cbs/docs/contributing.adoc#function-binding-and-callbacks

Change-Id: I326931a096b7184d403aea116248cffcde5c9775
Reviewed-on: http://gerrit.cloudera.org:8080/12146
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
  • Loading branch information
andrwng committed Jan 3, 2019
1 parent 91f104d commit 2fa5884
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions docs/contributing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,28 @@ in many places. When interfacing with that code, you can continue to use `shared

==== Function Binding and Callbacks

Existing code uses `boost::bind` and `boost::function` for function binding and
callbacks. For new code, use the `Callback` and `Bind` classes in `gutil` instead.
While less full-featured (`Bind` doesn't support argument
place holders, wrapped function pointers, or function objects), they provide
more options by the way of argument lifecycle management. For example, a
bound argument whose class extends `RefCounted` will be incremented during `Bind`
and decremented when the `Callback` goes out of scope.

See the large file comment in _gutil/callback.h_ for more details, and
_util/callback_bind-test.cc_ for examples.
Existing code uses `boost::bind` and `boost::function` to capture and manage
functors. For new code, use `std::bind` and `std::function`, which are
functionally equivalent.

Alternatively, the `Bind` and `Callback` classes in `gutil` may also be used to
capture functors. See _gutil/callback.h_ for more details and
_util/callback_bind-test.cc_ for examples. While less full-featured, they
provide different options from their counterparts by the way of argument
lifecycle management. The benefits of each are described below:

.`std::bind` and `std::function`
[none]
* natively supports binding `shared_ptr` and `weak_ptr` objects, so a bound
smartpointer argument will increment its count during `bind`, and decrement it
when the `function` leaves scope
* supports argument placeholders, wrapped function pointers, and function objects

.`Bind` and `Callback`
[none]
* natively supports binding `RefCounted` objects, so a bound argument whose
class extends `RefCounted` will increment its count during `Bind` and decrement
it when the `Callback` goes out of scope

==== GFlags

Expand Down

0 comments on commit 2fa5884

Please sign in to comment.