有些C++对象没有复制构造函数,但有移动构造函数.例如,boost :: promise.如何使用移动构造函数绑定这些对象?
#include <boost/thread.hpp>
void fullfil_1(boost::promise<int>& prom, int x)
{
prom.set_value(x);
}
boost::function<void()> get_functor()
{
// boost::promise is not copyable, but movable
boost::promise<int> pi;
// compilation error
boost::function<void()> f_set_one = boost::bind(&fullfil_1, pi, 1);
// compilation error as well
boost::function<void()> f_set_one = boost::bind(&fullfil_1, std::move(pi), 1);
// PS. I know, it is possible to bind a pointer to the object instead of
// the object itself. But it is weird solution, in this case I will have
// to take cake …Run Code Online (Sandbox Code Playgroud) 是否有与像STL功能的任何文库std::sort(),std::binary_search(),std::lower_bound(),std::upper_bound()接受(对大其返回-1上更小,0上相等,1)3路比较谓词而不是更少谓词(上少真,假上等于或大)?
当然,较少的谓词可以很容易地从现有的3向谓词(例如[](A a, B b) { return compare3(a,b)<0; })中得出,但这会导致对谓词的额外调用次数.
如何比较boost :: variant以使其成为std :: map的关键?似乎没有为boost :: variant定义operator <()