Tag: boost

为什么std :: function不平等?

这个问题也适用于boost::function和std::tr1::function 。 std::function不相等: #include <functional> void foo() { } int main() { std::function<void()> f(foo), g(foo); bool are_equal(f == g); // Error: f and g are not equality comparable } 在C ++ 11中, operator==和operator!= overload是不存在的。 在早期的C ++ 11草案中,重载被声明为删除(N3092§20.8.14.2): // deleted overloads close possible hole in the type system 它没有说出“types系统中可能存在的漏洞”是什么。 在TR1和Boost中,重载是声明的,但没有定义。 TR1规范注释(N1836§3.7.2.6): 这些成员函数应该是未定义的。 [ 注意:类似布尔的转换会打开一个漏洞,通过==或!=来比较两个函数实例。 这些未定义的void操作符closures了漏洞,并确保编译时错误。 – […]

如何通过不同的std :: vector的值对std :: vector进行sorting?

我有几个std::vector ,都是相同的长度。 我想对这些向量之一进行sorting,并将相同的转换应用于所有其他向量。 有没有一个干净的方式做到这一点? (最好使用STL或Boost)? 一些向量保存int s,其中一些std::strings 。 伪代码: std::vector<int> Index = { 3, 1, 2 }; std::vector<std::string> Values = { "Third", "First", "Second" }; Transformation = sort(Index); Index is now { 1, 2, 3}; … magic happens as Transformation is applied to Values … Values are now { "First", "Second", "Third" };

如何在C ++中使用boost来创build线程池?

如何在C ++中使用boost来创build线程池,以及如何将任务分配给线程池?

为什么不能在C ++ 0x模式下使用libc ++连接这个boost :: program_options例子?

编译boost :: program_options的示例代码: http : //svn.boost.org/svn/boost/trunk/libs/program_options/example/first.cpp …在MacOS Lion(10.7.2)上,使用安装了MacPorts的boost-1.48.0: $ clang++ -v Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn) Target: x86_64-apple-darwin11.2.0 Thread model: posix $ clang++ -std=c++0x –stdlib=libc++ -lc++ -I/opt/local/include -L/opt/local/lib -lboost_program_options first.cpp -o first Undefined symbols for architecture x86_64: "boost::program_options::options_description::options_description(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int, unsigned int)", referenced from: _main in cc-6QQcwm.o […]

使用boost或STL对C ++中的压缩(locking)容器进行sorting

我想做什么:我想sorting2或3,或N个向量,locking在一起, 而不复制到一个元组中。 也就是说,把冗长留在一边,就像: vector<int> v1 = { 1, 2, 3, 4, 5}; vector<double> v2 = { 11, 22, 33, 44, 55}; vector<long> v3 = {111, 222, 333, 444, 555}; typedef tuple<int&,double&,long&> tup_t; sort(zip(v1,v2,v3),[](tup_t t1, tup_t t2){ return t1.get<0>() > t2.get<0>(); }); for(auto& t : zip(v1,v2,v3)) cout << t.get<0>() << " " << t.get<1>() << " […]

`enable_shared_from_this`有什么用处?

我在阅读Boost.Asio示例时遇到了enable_shared_from_this ,在阅读完文档之后,我仍然不知道如何正确使用它。 有人可以给我一个例子和/或解释什么时候使用这个类是有道理的。

如何在Visual Studio 2010中使用Boost

关于如何在Visual Studio 2010中的空项目中使用Boost库,一步一步的解释是什么?

为什么在使用boost :: asio时需要连接每个连接?

我正在审查Boost网站上的HTTP Server 3示例。 请你们解释为什么我需要每个连接的strand ? 正如我所看到的,我们只在read事件的处理程序中调用read_some 。 所以基本上read_some调用是顺序的,因此不需要链(和第3段的第2项说相同的事情)。 multithreading环境中的风险在哪里?