idiomatic D: what to use instead of pointers in constructing a tree data structure?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 8 07:55:05 PST 2015
On 1/8/15 12:15 AM, Meta wrote:
> On Wednesday, 7 January 2015 at 23:27:19 UTC, anonymous wrote:
>> Don't do this without `dup`ing. Quoting the documentation:
>
> Oh, whoops. I thought those special variadic args were always allocated
> on the heap.
Nope,
Which makes it annoying, what if the argument IS passed on the heap?
Fortunately, there is a solution (one I use in dcollections):
foo(T[] x...)
foo(T[] x)
Can be overloaded. If you ever pass in parameters one at a time, the
first is called, and x is guaranteed to be on the stack.
The second is called with an actual array only, you are able to not
'dup', and just warn people that x will NOT be dup'd in that case.
-Steve
More information about the Digitalmars-d-learn
mailing list