I'm pretty sure that I know the answer to this question (thinking no), but is it possible to safely accept / return std :: function by value in the API (across module boundaries)?
I think no, because I donβt think there is any guarantee that the implementation of one std :: function provider is compatible with others. Is that the case?
If the answer is not the same as I suspect, how do you all deal with this? I may have to resort to implementing my own or just avoid things like std :: function, together (for example: working with function pointers or functions). :-( I found myself doing this in many cases before (inventing a lot C ++ standard library and, unfortunately, even creating our own STL-compatible vector type with support for both ctor and fill ctor, custom allocators, etc. was certainly not funny, and I doubt it was as good as standard implementations) simply because you can dynamically and link to a library that has, say, an implementation of MSDV 2010 std :: function from a binary file written in mingw, for example
An alternative, of course, is not to use these C ++ features in general in our API and use, say, the C interface, but for us it will be quite expensive, since we use our API as a central API for development both internally and for third-party developers.
source share