dimanche 2 octobre 2016

std::unique_ptr with lambda custom deleter doesnt compile

Can't find whats the problem in following code

std::unique_ptr<CFStringRef, std::function<void(CFStringRef)>>
cfstr(CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8),
                                 [](CFStringRef obj){
                                     CFRelease(obj);
                                 });

CFStringCreateWithCString should return correct type as per CFStringCreateWithCString documentation

Error:

/Applications/http://ift.tt/1jmLxI7 -x c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=c++11 -stdlib=libc++ -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wno-unused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -isysroot /Applications/http://ift.tt/1huDuHE -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.7 -g -fvisibility-inlines-hidden -Wno-sign-conversion -D_DEBUG -DDEBUG -MMD -MT dependencies -MF -c DynamicStore.cpp -o DynamicStore.o

DynamicStore.cpp:29:5: error: no matching constructor for initialization of 'std::unique_ptr<CFStringRef, std::function<void (CFStringRef)> >'
    cfstr((CFStringRef)CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8),

Aucun commentaire:

Enregistrer un commentaire