1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
int main() {
auto delegate1 = brDelegate::create<MachineGun, double, std::string>
([] (double caliber, const std::string& name) -> std::shared_ptr<MachineGun>
{ return std::make_shared<MachineGun>(caliber, name); });
auto gun = delegate1->run<MachineGun, double, std::string>(50.0, "BAR");
// *** type of gun is std::shared_ptr<MachineGun>
// *** this will compile cleanly
auto test = resolve<Armament, std::shared_ptr<Gun>>( gun );
// *** equivalent to auto test = resolve<Armament, std::shared_ptr<Gun>>( std::shared_ptr<Gun>(gun) ) ; // rvalue
auto delegate2 = brDelegate::create<brTexture, brTexture::eTextureType>
([] (brTexture::eTextureType type) -> std::shared_ptr<brTexture>
{ return std::make_shared<brGL3Texture>(type); });
auto texture0 = std::make_shared<brGL3Texture>(brTexture::TYPE_TEXTURE_2D);
// *** type of texture0 is std::shared_ptr<brGL3Texture>
// *** this will compile cleanly
auto test0 = resolve<brGL3TextureSampler, std::shared_ptr<brTexture>>( texture0 ) ; // rvalue
// *** equivalent to auto test = resolve<brGL3TextureSampler, std::shared_ptr<brTexture>>( std::shared_ptr<brTexture>(texture0) ) ; // rvalue
auto texture = delegate2->run<brTexture, brTexture::eTextureType>(brTexture::TYPE_TEXTURE_2D);
// *** type of texture is std::shared_ptr<brTexture>
// auto test1 = resolve<brGL3TextureSampler, std::shared_ptr<brTexture>>( texture ) ; // lvalue
// *** error *** no conversion from std::shared_ptr<brTexture>& to std::shared_ptr<brTexture>&&
// *** this will compile cleanly
auto test2 = resolve<brGL3TextureSampler, std::shared_ptr<brTexture>>( std::shared_ptr<brTexture>(texture) ); // rvalue
// *** this will also compile cleanly; but donot use the object texture after this
auto test3 = resolve<brGL3TextureSampler, std::shared_ptr<brTexture>>( std::move(texture) ); // rvalue
}
| |