Boost logo

Boost Users :

Subject: [Boost-users] Apple "Block" closures and boost::function
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2012-05-26 10:41:52


I'm looking at using Apple's proprietary closure blocks as a substitute for C++ lambda
functions on a project that needs to be portable between Mac (LLVM 3.1, but not using the
C++0x dialect compiler switch) and Windows (Visual Studio 10). The project uses Boost.TR1
to supply std::tr1::function and related stuff on the Mac build.

Now I found that the compiler handles the nonstandard block objects in Functor-like
template situations in a manner perfectly analogous to C-style pointers to functions. I
can even assign one to a boost::function with no complaint!

The only issue seems to be that it never calls Block_copy/Block_release. So it works OK
for passing them to STL algorithms that uses them on the spot, but will probably do bad
things if used in general.

Does anybody have something ready-made, to efficiently add the copy/destroy semantics to
functors that hold such "blocks"? That would be much more efficient than wrapping them in
another layer. Or, any pointers to the Boost innerds for doing that myself?

Thanks,
—John


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net