#include <memory>
#include <inttypes.h>
#include <vector>
struct OtherClass
{
OtherClass() = default;
~OtherClass() = default;
OtherClass(const OtherClass&) = delete;
OtherClass& operator=(const OtherClass&) = delete;
OtherClass(OtherClass&&) = default;
OtherClass& operator=(OtherClass&&) = default;
};
struct Buf
{
static std::shared_ptr<Buf> Create(size_t count, const std::shared_ptr<OtherClass>*& others)
{
return std::make_shared<Buf>(count, others);
}
static std::shared_ptr<Buf> Create(size_t count, std::shared_ptr<OtherClass>*&& others)
{
return std::make_shared<Buf>(count, std::move(others));
}
Buf(size_t count, const std::shared_ptr<OtherClass>*& other)
{
others.reserve(count);
for(size_t i = 0; i < count; ++i) {
others.push_back(other[i]);
}
}
Buf(size_t count, std::shared_ptr<OtherClass>*&& other)
{
others.reserve(count);
for(size_t i = 0; i < count; ++i) {
others.push_back(std::move(other[i]));
}
}
Buf() = default;
~Buf() = default;
Buf(const Buf&) = delete;
Buf& operator=(const Buf&) = delete;
Buf(Buf&&) = default;
Buf& operator=(Buf&&) = default;
std::vector<std::shared_ptr<OtherClass>> others;
};
std::shared_ptr<Buf> buf;
int main()
{
std::shared_ptr<OtherClass> other;
//this calls Buf(size_t count, std::shared_ptr<OtherClass>*&& other)
//instead of
//Buf(size_t count, const std::shared_ptr<OtherClass>*& other)
//why?
buf = Buf::Create(1, &other);
//and this is ok, Buf(size_t count, std::shared_ptr<OtherClass>*&& other), because of std::move()
std::shared_ptr<OtherClass> other;
buf = Buf::Create(1, std::move(&other));
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}