C++11中,针对顺序容器(如vector、deque、list),新标准引入了三个新成员:emplace_front、emplace和emplace_back,这些操作构造而不是拷贝元素。这些操作分别对应push_front、insert和push_back,允许我们将元素放置在容器头部、一个指定 Read More
posted @ 2018-12-12 23:09 绿色冰点 Views(13166) Comments(0) Diggs(3) Edit
C++本身有引用(&),为什么C++11又引入了std::ref(或者std::cref)? 主要是考虑函数式编程(如std::bind)在使用时,是对参数直接拷贝,而不是引用。如下例子: Output: 上述代码在执行std::bind后,在函数f()中n1的值仍然是1,n2和n3改成了修改的值。 Read More
posted @ 2018-12-12 23:04 绿色冰点 Views(4148) Comments(0) Diggs(1) Edit
先说明一点:std::asyanc是std::future的高级封装, 一般我们不会直接使用std::futrue,而是使用对std::future的高级封装std::async。 下面分别说一下。 一、std::async基本用法 std::future可以从异步任务中获取结果,一般与std::a Read More
posted @ 2018-12-12 23:02 绿色冰点 Views(28204) Comments(3) Diggs(6) Edit