On Tue, Dec 3, 2013 at 3:41 AM, Patrick Walton <[email protected]> wrote: > On 12/3/13 12:34 AM, Val Markovic wrote: >> >> This is an interesting thread. A few points: >> >> - "box" makes a lot more sense than "new"; as others have pointed out, >> the latter maps to a different concept in C++ which makes it familiar in >> the worst way. >> - "Foo::init" is terrible, agreed, but "Foo::new" is less than ideal as >> well. "Foo::create" might be better. Just read this aloud: "this >> function news a value." What? That makes no sense. "This function >> creates a value." Much better, isn't it? Point being, it should be a >> verb. JavaScript does it with Object.create, so there's precedent. >> - placement new might be common in Servo and browser engines, but it's >> not that common in most C++. After 10 years and 200k+ LOC of C++ across >> many, many different programs and paradigms I've yet to use it once. >> Sure, that's just one person's experience but others seem to be echoing >> the same sentiment. I'm not saying let's not have placement new, just >> that we shouldn't put on an undeserved pedestal. > > > Rust and C++ are different. You don't use placement `new` for `shared_ptr` > in C++; however, you will use placement `new` (or `box`) for `RC` in Rust > (the equivalent). For this reason I suspect that placement `new` will be > much commoner in Rust than in C++. > > Patrick
To expand on this, C++ has functions like `make_shared` (C++11), `make_unique` (C++14) and even container methods to build an object in-place without a move (`emplace`, `emplace_back`, etc.). _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
