On Tuesday, 8 December 2015 at 05:13:51 UTC, Chris Wright wrote:
On Tue, 08 Dec 2015 14:12:02 +1100, Daniel Murphy wrote:
On 4/12/2015 8:38 AM, Chris Wright wrote:
An object reference is just a pointer, but we can't directly
cast it. So we make a pointer to it and cast that; the type
system
On 4/12/2015 8:38 AM, Chris Wright wrote:
An object reference is just a pointer, but we can't directly cast it. So
we make a pointer to it and cast that; the type system allows it. Now we
can access the data that the object reference refers to directly.
Casting is fine too: cast(void*)classRef
On Tue, 08 Dec 2015 14:12:02 +1100, Daniel Murphy wrote:
> On 4/12/2015 8:38 AM, Chris Wright wrote:
>> An object reference is just a pointer, but we can't directly cast it.
>> So we make a pointer to it and cast that; the type system allows it.
>> Now we can access the data that the object
On 12/05/2015 01:32 AM, Observer wrote:
Won't clear(c); do the trick? ((pp187-188 of TDPL)
clear() has been renamed as destroy() but it won't work by itself
because the OP wants a reusable object. I think, in addition to
destroy(), the default constructor should be run:
On Sat, 05 Dec 2015 07:48:16 -0800, Ali Çehreli wrote:
> On 12/05/2015 01:32 AM, Observer wrote:
>
>> Won't clear(c); do the trick? ((pp187-188 of TDPL)
>
> clear() has been renamed as destroy() but it won't work by itself
> because the OP wants a reusable object. I think, in addition to
>
On Saturday, 5 December 2015 at 16:28:18 UTC, Chris Wright wrote:
The default constructor doesn't set default field values,
though, which is why my solution involved copying
ClassInfo.init.
Thanks, this is a handy factoid. Reminds me of the whole __dtor
vs __xdtor debacle.
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
Given
class C
{
// lots of members
}
and a function
f(C c)
{
}
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values?
Something along
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
...
Unless I'm missing something very important: Isn't that
essentially what the `out` attribute on a function parameter does?
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
...
I think reflection will be a bad choice for this because of
private members and what not.
I think the correct way is:
void reset(C)(ref C c)
{
static if(is(C == class))
{
auto init =
On Friday, 4 December 2015 at 04:08:33 UTC, Tofu Ninja wrote:
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
...
I think reflection will be a bad choice for this because of
private members and what not.
I think the correct way is:
void reset(C)(ref C c)
{
static
On Thursday, 3 December 2015 at 21:13:59 UTC, Nordlöw wrote:
Need to assert that not a function and mutability
(std.traits.isMutable)
Yeah you need to do that.
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
Given
class C
{
// lots of members
}
and a function
f(C c)
{
}
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values?
Something along
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
Something along
foreach(ref member; __traits(allMembers, c))
{
member = typeof(member).init;
}
This works for me:
void resetAllMembers(T)(T c)
if (is(T == class))
{
foreach (ref m; c.tupleof)
{
On Thursday, 3 December 2015 at 21:38:48 UTC, Chris Wright wrote:
The terrible way is something like:
void reset(Object o)
in {
assert(!(o is null));
}
body {
auto p = cast(ubyte*)*cast(void**)
auto ci = o.classinfo;
auto init = cast(ubyte)ci.init;
p[0..init.length] = init[];
if
On Thu, 03 Dec 2015 21:55:04 +, Nordlöw wrote:
> On Thursday, 3 December 2015 at 21:38:48 UTC, Chris Wright wrote:
>> The terrible way is something like:
>>
>> void reset(Object o)
>> in {
>> assert(!(o is null));
>> }
>> body {
>> auto p = cast(ubyte*)*cast(void**)
>> auto ci =
Given
class C
{
// lots of members
}
and a function
f(C c)
{
}
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values? Something
along
foreach(ref member; __traits(allMembers, c))
{
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values?
You could always copy the init back over it. For a struct:
s = Struct.init;
for a class... well, the code is a lot
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
Given
class C
{
// lots of members
}
and a function
f(C c)
{
}
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values?
Something along
Haven't compiled but it should look something like this:
foreach(member; __traits(allMembers, typeof(c)))
__traits(getMember, c, member) = typeof(__traits(getMember,
c, member)).init;
On Thursday, 3 December 2015 at 21:08:30 UTC, Sebastiaan Koppe
wrote:
Haven't compiled but it should look something like this:
foreach(member; __traits(allMembers, typeof(c)))
__traits(getMember, c, member) = typeof(__traits(getMember,
c, member)).init;
Need to assert that not a function
The terrible way is something like:
void reset(Object o)
in {
assert(!(o is null));
}
body {
auto p = cast(ubyte*)*cast(void**)
auto ci = o.classinfo;
auto init = cast(ubyte)ci.init;
p[0..init.length] = init[];
if (ci.defaultConstructor) {
ci.defaultConstructor(o);
} else {
21 matches
Mail list logo