Skip to content

Instantly share code, notes, and snippets.

@benjamn
Created March 9, 2009 23:16
Show Gist options
  • Save benjamn/76549 to your computer and use it in GitHub Desktop.
Save benjamn/76549 to your computer and use it in GitHub Desktop.
template <typename Callable, typename ResultPtr>
class nsRunnableFunctor
: public nsARunnableFunctor
{
Callable mCallable;
ResultPtr mResultPtr;
public:
nsRunnableFunctor(Callable callable, ResultPtr resultPtr)
: mCallable(callable)
, mResultPtr(resultPtr)
{}
nsresult Run()
{
// This line enforces everything that matters about ResultPtr and Callable:
// that mResultPtr can be dereferenced, that mCallable is callable with no
// arguments, that the result of this call is non-void, and that the
// result can be copied into the L-value resulting from the expression
// *mResultPtr. No other properties of the template parameters are in any
// way constrained, not even implicitly. Do I feel clever? Yes, I do.
*mResultPtr = mCallable();
return AfterRun();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment