[function] Bind to std::function if supported?
The boost::move library binds to std::move/T&&/etc. when the compiler supports such features, and only uses work-around mechanisms when the compiler lacks such support. Should we add similar support for boost::function? something like: #ifdef BOOST_FUNCTION_USE_STANDARD_LIBRARY_FUNCTION // alternative: #ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL #include <functional> namespace boost { using ::std::function; } #else // whatever boost::function currently does #endif // ... something similar for boost::bind and std::bind I haven't looked at boost::atomic yet, but we could also consider similar bindings to std::atomic if the library doesn't already do so.
2013/7/9 Andrew Ho
The boost::move library binds to std::move/T&&/etc. when the compiler supports such features, and only uses work-around mechanisms when the compiler lacks such support.
Should we add similar support for boost::function?
I don't think so. boost::function doesn't have exactly the same interface as std::function, unlike the case of 'move', which has consistent interface.
On Mon, Jul 8, 2013 at 10:34 PM, Andrew Ho
I haven't looked at boost::atomic yet, but we could also consider similar bindings to std::atomic if the library doesn't already do so.
std::atomic is also slightly different from boost::atomic (or rather, std::atomic_flag from boost::atomic_flag). Also, boost::atomic is better optimized than std::atomic on gcc prior to 4.7 and std::atomic cannot be used with structs with gcc prior to 4.8. Not sure what is the state of affairs on MSVC and other compilers.
std::atomic is also slightly different from boost::atomic (or rather, std::atomic_flag from boost::atomic_flag).
From the boost::atomic documentation:
It implements the interface as defined by the C++11 standard, but makes this feature available for platforms lacking system/compiler support for this particular C++11 feature.
If the interface it actually implements is different, perhaps boost::atomic's interface needs to change? I can't seem to find documentation for boost::atomic_flag (at least in the official online docs), either. Similarly, should we make such changes to boost::function/boost::bind? It does seem like changes at least to boost::function and most likely boost::bind would likely break old code, but I kind of view these libraries as "providing std library support for compilers/systems without support".
Also, boost::atomic is better optimized than std::atomic on gcc prior to 4.7 and std::atomic cannot be used with structs with gcc prior to 4.8. Not sure what is the state of affairs on MSVC and other compilers.
It doesn't need to specifically map to std::atomic if any compiler support is provided, we could build a list of compilers where std::atomic performs at least as well as boost::atomic, or better. something like: if compiler is compiler A, and compiler A version < x: use boost::atomic else if compiler is compiler B, and compiler B version < y: use boost::atomic ... else if compiler supports std::atomic: use std::atomic else: use boost::atomic As far as other libraries, I have benchmarked std::function vs. boost::function on VS2012 and preliminary results suggests std::function is at least as fast, if not faster compared to boost::function.
participants (3)
-
Andrew Ho
-
Andrey Semashev
-
鄭伯涵