小编Che*_*han的帖子

在C++ 11中实现复制和交换习惯用法的更好方法

我看到许多代码在复制和交换方面实现了五个规则,但我认为我们可以使用移动函数来替换交换函数,如下面的代码所示:

#include <algorithm>
#include <cstddef>

class DumbArray {
public:
    DumbArray(std::size_t size = 0)
        : size_(size), array_(size_ ? new int[size_]() : nullptr) {
    }

    DumbArray(const DumbArray& that)
        : size_(that.size_), array_(size_ ? new int[size_] : nullptr) {
        std::copy(that.array_, that.array_ + size_, array_);
    }

    DumbArray(DumbArray&& that) : DumbArray() {
        move_to_this(that);
    }

    ~DumbArray() {
        delete [] array_;
    }

    DumbArray& operator=(DumbArray that) {
        move_to_this(that);
        return *this;
    }

private:
    void move_to_this(DumbArray &that) {
        delete [] array_;
        array_ = that.array_;
        size_ = that.size_;
        that.array_ = nullptr;
        that.size_ …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

11
推荐指数
2
解决办法
2288
查看次数

是否由OS并行执行boost :: asio lib的async_*函数

最近我使用的是boost :: asio库,并对这些async_*函数有疑问.

假设我boost::asio::async_write()连续调用多个,async_write()即使io_service是单线程运行的,这些函数是否可能由底层操作系统并行执行

谢谢!

c++ boost boost-asio c++11

5
推荐指数
1
解决办法
213
查看次数

标签 统计

c++ ×2

c++11 ×2

boost ×1

boost-asio ×1