From: Felix Handte Date: Thu, 25 Aug 2016 00:42:37 +0000 (-0700) Subject: Easy: Mark folly::static_function_deleter::operator() const X-Git-Tag: v2016.08.29.00~12 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ff92b6ea53d4db75691784b0febfd3070913d2b6;p=folly.git Easy: Mark folly::static_function_deleter::operator() const Summary: First, folly::static_function_deleter::operator() is in fact a const operation, so this should be a reasonable change. The motivation for this is to make folly::ThreadLocalPtr and folly::static_function_deleter play nice with each other. Minimal example: ```lang=c++ void deleter(int* ptr) { free(ptr); } int main(int argc, char* argv[]) { folly::ThreadLocalPtr tl; tl.reset(std::unique_ptr>( new int(0))); return 0; } ``` Currently produces: ``` folly/ThreadLocal.h:207:7: error: no matching function for call to object of type 'const folly::static_function_deleter' delegate(ptr); ^~~~~~~~ Test.cpp:10:6: note: in instantiation of function template specialization 'folly::ThreadLocalPtr::reset, void>' requested here tl.reset(std::unique_ptr>(new int(0))); ^ folly/Memory.h:91:8: note: candidate function not viable: 'this' argument has type 'const folly::static_function_deleter', but method is not marked const void operator()(T* t) { f(t); } ^ 1 error generated. ``` With the fix, the build succeeds. Reviewed By: yfeldblum Differential Revision: D3764624 fbshipit-source-id: c28c791b79f1415704c205c36bfda2d888d6c010 --- diff --git a/folly/Memory.h b/folly/Memory.h index 81ac176c..62490f90 100644 --- a/folly/Memory.h +++ b/folly/Memory.h @@ -88,7 +88,9 @@ make_unique(Args&&...) = delete; template struct static_function_deleter { - void operator()(T* t) { f(t); } + void operator()(T* t) const { + f(t); + } }; /**