Is there any difference between the two? Or am I safe to replace every occurrence of boost::bind
by std::bind
in my code and thereby remove the dependence on Boost?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Besides the listed above, boost::bind has an important extension point: get_pointer() function that allows integrating boost::bind with any smart pointer, eg. ATL::CComPtr etc. http://www.boost.org/doc/libs/1_49_0/libs/bind/mem_fn.html#get_pointer
As a result, with boost::bind you can also bind a weak_ptr: http://lists.boost.org/Archives/boost/2012/01/189529.php
boost::bind
has overloaded relational operators,std::bind
does not.boost::bind
supports non-default calling conventions,std::bind
is not guaranteed to (standard library implementations may offer this as an extension).boost::bind
provides a direct mechanism to allow one to prevent eager evaluation of nested bind expressions (boost::protect
),std::bind
does not. (That said, one can useboost::protect
withstd::bind
if they want, or trivially reimplement it on their own.)std::bind
provides a direct mechanism to allow one to treat any user defined functor as a nested bind expression in order to force eager evaluation (std::is_bind_expression
: [func.bind.isbind]/1, [func.bind.bind]/10),boost::bind
does not.I don't have the full answer but
std::bind
will use variadic templates rather than parameter lists.The placeholders are in
std::placeholders
as instd::placeholders::_1
rather than the global namespace.I alias the namespace to stdph with
Apart from that I have had no problems updating to C++11
Besides the several differences cited on the other answers, here are two other differences:
boost::bind
seems to deal with overloaded function names in some situations, whereasstd::bind
does not deal with them in the same way. See c++11 faq(using gcc 4.7.2, boost lib version 1_54)
So if you simply replaced all
boost::bind
withstd::bind
, your build could break.std::bind
can seamlessly bind to c++11 lambda types, whereasboost::bind
as of boost 1.54 seems to require input from the user (unless return_type is defined). See boost doc(using gcc 4.7.2, boost lib version 1_54)
So, if you simply replaced all
std::bind
withboost::bind
, your build could also break.