foo!(bar) ==> foo{bar} ==> foo[bar] (just Brackets)

Benji Smith dlanguage at benjismith.net
Fri Oct 17 16:45:52 PDT 2008


Don wrote:
> Using square brackets would certainly fit with Walter's goal of making 
> templates less threatening for newcomers.
> It would be pretty cool to teach a newbie:
> 
> int[] a;
> int[double] b;  // this is an AA
> priorityqueue[double] c; // this is a template

Actually, with Andrei's "Array" template introducing template syntax for 
arrays, I think there could be a convincing argument that all arrays 
(associative or otherwise) would benefit from a template-like declaration.

After all, a standard garden-variety array is actually very much like a 
type-specialized "sequence" container.

Templates like these could entirely replace the builtin array types, and 
I think everyone, from beginner to pro, would be comfortable with the 
syntax:

   // Maybe make the names explicit...
   auto a = DynamicArray[int];
   auto b = StaticArray[int, 3];

   // Or the name could be the same, with the template arguments
   // determining the static/dynamic implementation...
   auto c = Array[int];
   auto d = Array[int, 3];

   // Syntax between arrays, standard containers, and library
   // containers would be syntactically similar. Very nice.
   auto e = AssociativeArray[int, double];
   auto f = HashMap[int, double];
   auto g = PriorityQueue[double];

I actually think it's a very nice, totally workable idea.

--benji



More information about the Digitalmars-d mailing list