D move semantics

piotrekg2 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 30 09:12:41 PDT 2017


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();
}



More information about the Digitalmars-d-learn mailing list