On Sat, 12 Nov 2011 16:29:01 +0100, Andrei Alexandrescu
<[email protected]> wrote:
On 11/12/11 8:39 AM, deadalnix wrote:
Hi all,
We recently had a discution on #D about copying a struct on the heap and
getting a pointer to it.
We come up with the following solution (Thanks to CyberShadow !) :
struct S;
S s; // Allocated locally.
[s].ptr; // Get a pointer to a copy in the heap of the struct
This should work:
S s;
auto p = new S(s);
It's a bug in the compiler if it doesn't. Unfortunately it doesn't for
primitive types, e.g. new int(5) does not work.
Andrei
Not so sure about built-in types. It's preferable for generic code to
define 'Type(Expression)'
as initializer, but is there a consensus for 'int(3)'?
Also as it is allowed for structs there should be no ambiguities with
function signatures, still this needs a thorough thought.