What is the idiomatic D code equivalent to this c++ code?

class Block
{
public:
  Block()
    : data_(new char[4096])
  {}

  ...

  // NOTE: both members marked noexcept
  Block(Block &&rhs) noexcept = default;
  Block& operator=(Block &&rhs) noexcept = default;

  ...

private:
  std::unique_ptr<char> data_;
};

// What is the equivalent of std::vector, the closest thing I could find is
// std.container.array
std::vector<Block> blocks;

for (int i = 0; i < 100; ++i) {
  // NOTE: blocks are moved when relocation happens
  // because of move-ctor and move-assign-operator marked noexcept
  blocks.emplace_back();
}

  • D move semantics piotrekg2 via Digitalmars-d-learn

Reply via email to