Topic: Default template arguments


Author: jason@cygnus.com (Jason Merrill)
Date: Wed, 20 Apr 1994 21:33:17 GMT
Raw View
>>>>> Allen B Taylor <allen@euniice.canada.dg.com> writes:

> Forgive me if someone else has already suggested this idea.  Has anyone
> on the standards committee given thought to default arguments for
> templates?

Yes, and they are allowed in the current working paper.

Jason




Author: allen@euniice.canada.dg.com (Allen B. Taylor)
Date: Mon, 18 Apr 94 18:28:44 GMT
Raw View
Forgive me if someone else has already suggested this idea.  Has anyone on the
standards committee given thought to default arguments for templates?  Here is
an example of how I think it would work:

 template <class ElementT, int size = 32>
 class Array
 { /*...*/ };

This template could be instantiated in one of two ways:

 Array<String, 10> arr1;  // Array of 10 String's
 Array<String> arr2;  // Array of 32 String's

This concept could also be applied to the class type arguments.  For example:

 template <class ElementT>
 class Queue
 { /*...*/ };
 template <class ElementT, class NodeT = Queue<ElementT> >
 class HashTable
 { /*...*/ };

This template could also be instantiated in one of two ways:

 HashTable<Record, Stack<Record> > ht1;
     // Hash table of Record's with a Stack
     // at each hash table entry
     // (assumes template for Stack exists)
 HashTable<Record> ht2;  // Hash table of Record's with a Queue
     // at each hash table entry

Comments welcome at allen_taylor@dgc.ceo.dg.com or allen@eUNiiCE.canada.dg.com.
---
Allen B. Taylor                       tel: (905)819-5326
Data General (Canada) Inc.            fax: (905)819-5417
2000 Argentia Road, Plaza 5           email: allen_taylor@dgc.ceo.dg.com
Mississauga, Ontario, Canada
L5R 2N7

These are my opinions, not my employers.