August 23, 2002
Walter wrote:
> "Pavel Minayev" <evilone@omen.ru> wrote in message
> news:CFN374913480596065@news.digitalmars.com...
> 
>>On Thu, 22 Aug 2002 14:02:13 -0700 Russell Lewis
>><spamhole-2001-07-16@deming-os.org> wrote:
>>
>>>>In that case, it serves to distinguish:
>>>>    instance Bar(int) x1;
>>>>from:
>>>>    instance Bar(int, int[]) x2;
>>>
>>>And the difference between the two is?
>>
>>The first one gets one argument, the second gets two. =)
> 
> 
> Yes, that's all it is. Think of it like function overloading.

Kind of like
    void foo(int a,int b) in { assert(a == b); } {...}
???

If that's the case, why are we reusing the "Bar" name rather than just defining a new template name that only takes one argument???


August 23, 2002
In article <ak5rgs$23m5$1@digitaldaemon.com>, Walter says...
>
>"Mac Reiter" <Mac_member@pathlink.com> wrote in message news:ak3agl$27qt$1@digitaldaemon.com...
>> I know that 'counted' would increase the complexity of the compiler, which
>you
[clip]
>
>The complexity comes from decrementing the counts of objects going out of scope, in the presence of exceptions. It did occur to me that if this was supported, it would also implicitly support the people who want deterministic destruction.

Yup.  Actually, I originally started thinking about a 'scoped' keyword whose sole purpose was to supply scoped destruction, but then I got to thinking about the times when you might want to make a new thing and pass it out of a function, but you still wanted its resources cleaned up as quickly as possible.  So I started thinking about reference counting and realized that it would handle the 'scoped' behavior as a trivial case.  Made me happy...

Mac


August 23, 2002
On Fri, 23 Aug 2002 10:50:45 -0700 "Juan Carlos Arevalo Baeza" <jcab@JCABs-Rumblings.com> wrote:

> "Pavel Minayev" <evilone@omen.ru> wrote in message
> --- mylibrary.d
> template Tpl(T) { ... }
> ---
> 
> --- myprogram.d
> using mylibrary;
> 
> class MyClass { ... }
> 
> instance Tpl(MyClass) TplMyClass; // Fails!!!
> ---

I think you CAN do it. What Walter meant is that you can use MyClass directly
from
Tpl if it is declared in the same module with Tpl. Otherwise, you have to pass
it
as a template argument.
August 23, 2002
On Fri, 23 Aug 2002 11:21:40 -0700 Russell Lewis <spamhole-2001-07-16@deming-os.org> wrote:

> If that's the case, why are we reusing the "Bar" name rather than just defining a new template name that only takes one argument???

It was just an example! It doesn't have to be useful or even have sense. =)
August 23, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:CFN374919430425@news.digitalmars.com...

> > --- mylibrary.d
> > template Tpl(T) { ... }
> > ---
> >
> > --- myprogram.d
> > using mylibrary;
> >
> > class MyClass { ... }
> >
> > instance Tpl(MyClass) TplMyClass; // Fails!!!
> > ---
>
> I think you CAN do it. What Walter meant is that you can use MyClass
directly
> from
> Tpl if it is declared in the same module with Tpl. Otherwise, you have to
pass
> it
> as a template argument.

   Well, that's not what I was asking to Walter.

"TemplateInstantiations are always performed
in the scope of where the TemplateDeclaration is declared, with the addition
of the template parameters being declared as aliases for their deduced
types"

   Let's update my second example:

--- mylibrary.d
template Tpl(T) {
  void tplfunc(T t) {
    func(t);
  }
}
---

--- myprogram.d
using mylibrary;

class MyClass { ... }

void func(MyClass) { ... }

instance Tpl(MyClass) TplMyClass; // Fails!!!
---

Salutaciones,
                       JCAB



August 24, 2002
"Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D667D34.3090803@deming-os.org...
> Walter wrote:
> > "Pavel Minayev" <evilone@omen.ru> wrote in message news:CFN374913480596065@news.digitalmars.com...
> >
> >>On Thu, 22 Aug 2002 14:02:13 -0700 Russell Lewis <spamhole-2001-07-16@deming-os.org> wrote:
> >>
> >>>>In that case, it serves to distinguish:
> >>>>    instance Bar(int) x1;
> >>>>from:
> >>>>    instance Bar(int, int[]) x2;
> >>>
> >>>And the difference between the two is?
> >>
> >>The first one gets one argument, the second gets two. =)
> >
> >
> > Yes, that's all it is. Think of it like function overloading.
>
> Kind of like
>      void foo(int a,int b) in { assert(a == b); } {...}
> ???
>
> If that's the case, why are we reusing the "Bar" name rather than just defining a new template name that only takes one argument???

Because Bar(int, int[]) is a specialization of Bar(T, U).


August 24, 2002
"Juan Carlos Arevalo Baeza" <jcab@JCABs-Rumblings.com> wrote in message news:ak3fd7$2dhu$1@digitaldaemon.com...
>    So you can't really use templates taken from a library with
user-defined
> types unless those user defined types are already known to the library?

Yes you can, if you pass the user defined type as a template argument.


>    I know you don't like forward declarations, but they might be warranted
> in the case of templates:
>
> template Tpl(T) {
>   exists void func(T); // forward declaration...
>   void anotherfunc(T t) {
>     func(t);
>   }
> }
>
>    This would allow you to eliminate all problems with dependent names.
> It'll also allow the compiler to do even better error messages for invalid
> instantiations. In a way, you can consider this as compile-time contracts
> for templates.

You can do things like:

    template Tpl(T)
    {
            T.func(t);
    }

Won't that fit the bill?


August 24, 2002
"Juan Carlos Arevalo Baeza" <jcab@JCABs-Rumblings.com> wrote in message news:ak5s95$24i6$1@digitaldaemon.com...
>    But not unless those types were visible at the point where the template
> was declared. So:
>
> --- mylibrary.d
> template Tpl(T) { ... }
> ---
>
> --- myprogram.d
> using mylibrary;
>
> class MyClass { ... }
>
> instance Tpl(MyClass) TplMyClass; // Fails!!!
> ---
>
>    That's what Walter seems to be saying. That the instantiation fails
> because MyClass is not visible in mylibrary.d. And that's what I have a
> problem with.

Anything passed as a template argument *is* visible.


August 24, 2002
"Juan Carlos Arevalo Baeza" <jcab@JCABs-Rumblings.com> wrote in message news:ak687r$2h6e$1@digitaldaemon.com...
> "TemplateInstantiations are always performed
> in the scope of where the TemplateDeclaration is declared, with the
addition
> of the template parameters being declared as aliases for their deduced types"
>
>    Let's update my second example:
>
> --- mylibrary.d
> template Tpl(T) {
>   void tplfunc(T t) {
>     func(t);
>   }
> }
> ---
>
> --- myprogram.d
> using mylibrary;
>
> class MyClass { ... }
>
> void func(MyClass) { ... }
>
> instance Tpl(MyClass) TplMyClass; // Fails!!!

Yes, that will fail. To make it work, func(MyClass) would need to be a class member of some class passed as a template argument.


August 24, 2002
I think that can work if it is prefaced by the keyword "instance".

"Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:ak36qj$23r4$1@digitaldaemon.com...
> It's still explicit, it just isn't a declaration by itself, it's part of another declaration or even part of a statement.  Legal wherever a
typespec
> or field reference is legal.
>
> Sean
>
> "Walter" <walter@digitalmars.com> wrote in message news:ak0qju$37o$1@digitaldaemon.com...
> > I hear you, but I want to try it with explicit instantiation names
first.
> > The reason is because I find templated code with lots of implicit instantiations to be totally unreadable.
> >
> >
> > "Pavel Minayev" <evilone@omen.ru> wrote in message
> > news:CFN374899452836458@news.digitalmars.com...
> > Container(int).Stack s;
> > This is to avoid cluttering the namespace with continuous lists of
> > instantiations (which is going to happen with any large program
> > using templates extensively).
>
>
>