August 24, 2002
"Mac Reiter" <Mac_member@pathlink.com> wrote in message news:ak5v0i$277b$1@digitaldaemon.com...
> 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...

It's pretty cool when solving one problem provides a trivial solution to an apparently unrelated problem.


August 24, 2002
"Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D655282.5030402@deming-os.org...
> I could see somebody wanting to do something like this:
>
> template List(X) {
>      class List {...};
> };
> template Thingy(A, List(A).List) {...};
>
> However, since we can't refer to template instances that way - we have to instantiate them explictly - I don't see any way to do this with the current template syntax.  Do you have any ideas how?

I could see doing that with:

template Thingy(A,  instance List(A).List) {...};



August 24, 2002
"Sean L. Palmer" <seanpalmer@earthlink.net> wrote in message news:ak36kl$23os$1@digitaldaemon.com...
> It would also be real nice if version() statements inside the template
could
> access the supplied actual template parameters.
>
> template Foo(T)
> {
>   version(T.class.string == "int")
>   {
>      // do int thingy
>   }
>   else
>   {
>     // do generic thingy
>   }
> }
>
> This can be simpler than specialization and is something I sorely miss in C++.

Yes, I've been thinking about that. It is a good idea, but there are many ways to do it.


August 24, 2002
On Fri, 23 Aug 2002 20:40:53 -0700 "Walter" <walter@digitalmars.com> wrote:

> I think that can work if it is prefaced by the keyword "instance".

Great! So, we could write?

	instance Container(double).deque q;
August 24, 2002
On Fri, 23 Aug 2002 20:40:15 -0700 "Walter" <walter@digitalmars.com> wrote:

>>    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.

To fix it:

	template Tpl(T, Func)
	{
		void tplfunc(T t) { Func.call(t); }
	}

	class MyClass { ... }

	void func(MyClass) { ... }

	class Func_MyClass
	{
		static void call(MyClass x) { func x; }
	}

	instance Tpl(MyClass, Func_MyClass) TplMyClass;    // Works!
August 24, 2002
Yes.

"Pavel Minayev" <evilone@omen.ru> wrote in message
news:CFN374924726702083@news.digitalmars.com...
On Fri, 23 Aug 2002 20:40:53 -0700 "Walter" <walter@digitalmars.com> wrote:

> I think that can work if it is prefaced by the keyword "instance".

Great! So, we could write?

instance Container(double).deque q;


August 26, 2002
"Walter" <walter@digitalmars.com> wrote in message news:ak0rom$app$2@digitaldaemon.com...
>
> "Mac Reiter" <Mac_member@pathlink.com> wrote in message news:ak0ltg$2hjd$1@digitaldaemon.com...
> > Thank you.  I hadn't quite grokked that a template was a thing entirely
to
> > itself.  The extra level of indirection (myfoo.abc rather than just
> abc(int))
> > had not really clicked.  Now that I see that, the RedBlack(char)
question
> goes
> > away.
>
> Yup. It's perilous to break from the C++ mindset on how it should work
<g>.

But do we want that extra indirection, after all?
In practice you usually need class templates.
You will end up typedef-ing everything, to avoid the burden of the
unnecessary indirection.

typedef   RedBlackTree  instance RBT_Template(char).TheClassInside;

Makes me feel like Java, with all the superfluous indirections.
And class templates also allow for function templates as static member
functions.

Sorry if this was already metioned. I don't have the time to read all the hundreds of mails in this thread.

Yours,
Sandor


August 26, 2002
"Walter" <walter@digitalmars.com> wrote in message news:ak757j$dr2$1@digitaldaemon.com...
>
> "Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D655282.5030402@deming-os.org...
> > I could see somebody wanting to do something like this:
> >
> > template List(X) {
> >      class List {...};
> > };
> > template Thingy(A, List(A).List) {...};
> >
> > However, since we can't refer to template instances that way - we have to instantiate them explictly - I don't see any way to do this with the current template syntax.  Do you have any ideas how?
>
> I could see doing that with:
>
> template Thingy(A,  instance List(A).List) {...};
>

Why would you need to pass on a completely dependent type as a seperate type parameter?

template Thingy(A) {
  alias  ListType instance List(A).List;
  ....
}

But how could you write a template with two arguments, one partially dependent on the other? Is this OK? :

template AdvancedList(E, F) { ... }

template Thingy(A, B : instance AdvancedList(A, C)) { ... }

Please correct me if wrong. I was intended to create a template whose second type argument is an instance of AdvancedList,  with the restriction that this AdvancedL:ist instance should be instatiated with the "A" type as the first type parameter. I supposed that there is no type named "C".

Another thing. Quoting template.html:

template Bar(D, D : D[]) { }

Is this valid?! You should give unique names to your type parameters. The
first type parameter is called "D", and the second?
Also I find bewildering the syntax:
D : D[]
Does this mean that the second type parameter "D" is an array composed of
elements of its own type? (Infinite recursion)

Yours,
Sandor


August 26, 2002
Walter wrote:
> "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).

Ok, got you so far.  So why declare it as
    template Bar(D, D : D[]) {...}
rather than
    template Bar(D, UNUSED_PARAM : D[]) {...}
???

The former looks like you're declaring the same parameter twice, with two different usages.

August 26, 2002
"Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D6A69CC.5050106@deming-os.org...
> > Because Bar(int, int[]) is a specialization of Bar(T, U).
> Ok, got you so far.  So why declare it as
>      template Bar(D, D : D[]) {...}
> rather than
>      template Bar(D, UNUSED_PARAM : D[]) {...}
> ???
>
> The former looks like you're declaring the same parameter twice, with two different usages.

It could be:
    (D, :D[])
but I thought the : might appear invisible like that.