Thread overview
Auto classes are limiting
May 07, 2004
Vathix
May 07, 2004
Andy Friesen
May 07, 2004
Vathix
May 10, 2004
Stewart Gordon
May 11, 2004
Matthew
May 07, 2004
If a class is defined as auto, I am unable to keep an instance alive longer than its scope. I would like there to be a way to specify non-auto. Most of the time I want to immediately destruct a memory mapped file, but sometime I might want to keep it around for awhile; I'd have to rewrite or modify the code!

--
Christopher E. Miller

May 07, 2004
Vathix wrote:
> If a class is defined as auto, I am unable to keep an instance alive longer than its scope. I would like there to be a way to specify non-auto. Most of the time I want to immediately destruct a memory mapped file, but sometime I might want to keep it around for awhile; I'd have to rewrite or modify the code!

You're right, they are.  On the bright side, you don't have to use auto that way.  Just write the class itself as non-auto, and use auto instances as needed.

This is perfectly legal:

    class A {
        ...
    }

    A foo() {
        auto A a = new A();
        A b = new A();

        // a should be cleaned up when the function is done, b will not,
        // as it was not declared as auto
        return b;
    }

 -- andy
May 07, 2004
In article <c7ggfk$v9r$1@digitaldaemon.com>, andy@ikagames.com says...
>This is perfectly legal:
>
>     class A {
>         ...
>     }
>
>     A foo() {
>         auto A a = new A();
>         A b = new A();
>
>         // a should be cleaned up when the function is done, b will not,
>         // as it was not declared as auto
>         return b;
>     }
>
>  -- andy

Right, but I mean when using someone else's code; like std.mmfile.MmFile is auto, so I'm stuck with an auto class, or I have to use my own code. (By the way, when I click std.mmfile at the top of phobos.html, it doesn't scroll down to it because the <A> tag is incorrect.)


-- 
Christopher E. Miller

May 10, 2004
Vathix wrote:

> In article <c7ggfk$v9r$1@digitaldaemon.com>, andy@ikagames.com says...
> 
>>This is perfectly legal:
>>
>>    class A {
>>        ...
>>    }
>>
>>    A foo() {
>>        auto A a = new A();
>>        A b = new A();
>>
>>        // a should be cleaned up when the function is done, b will not,
>>        // as it was not declared as auto
>>        return b;
>>    }
>>
>> -- andy
> 
> 
> Right, but I mean when using someone else's code; like std.mmfile.MmFile is auto, so I'm stuck with an auto class, or I have to use my own code. (By the way, when I click std.mmfile at the top of phobos.html, it doesn't scroll down to it because the <A> tag is incorrect.)

I don't see why that particular class has to be auto either.  Why should an mmfile have to have function-local scope whether the programmer likes it or not?

I suppose a possible workaround is to wrap the mmfile in a thread....

Stewart.

-- 
My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.
May 11, 2004
"Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:c7o59r$2u8c$1@digitaldaemon.com...
> Vathix wrote:
>
> > In article <c7ggfk$v9r$1@digitaldaemon.com>, andy@ikagames.com says...
> >
> >>This is perfectly legal:
> >>
> >>    class A {
> >>        ...
> >>    }
> >>
> >>    A foo() {
> >>        auto A a = new A();
> >>        A b = new A();
> >>
> >>        // a should be cleaned up when the function is done, b will not,
> >>        // as it was not declared as auto
> >>        return b;
> >>    }
> >>
> >> -- andy
> >
> >
> > Right, but I mean when using someone else's code; like std.mmfile.MmFile is auto, so I'm stuck with an auto class, or I have to use my own code. (By the way, when I click std.mmfile at the top of phobos.html, it doesn't scroll
down
> > to it because the <A> tag is incorrect.)
>
> I don't see why that particular class has to be auto either.  Why should an mmfile have to have function-local scope whether the programmer likes it or not?

That was the way Walter wanted it, and it seemed ok to me at the time. I concur that it should probably not be.

Perhaps one of you could post is as a bug on the bugs NG, and we'll fix it for next time?

>
> I suppose a possible workaround is to wrap the mmfile in a thread....
>
> Stewart.
>
> -- 
> My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.