Topic: Proposal: template default arguments


Author: niklas@appli.se (Niklas Hallqvist)
Date: 11 Feb 91 15:20:09 GMT
Raw View
 Hello!

 I've just read chapter 14 of the ARM and are thrilled by
the possibilities with templates, especially together with MI.
Up to this point I've been experimenting with CPP macros and the
GNU genclass utility.  However, there is a slight change I'd like
to see: default template arguments.  For example:

template<class T = void*, int size = 1024> class Stack {
private:
  T rep[size];
public:
  ...
};

void foo();
  Stack<> a;  // A Stack<void*, 1024>
  Stack<char*> b; // A Stack<char*, 1024>
  Stack<char*, 512> c; // Well, what do you think!!!
}

How about this?  Are there any problems implementing this?  It's
quite consistent with the way ordinary default arguments work.
And please, don't flame me for wanting to throw in yet another feature
in the language.  I wouldn't have posted this if didn't know that
it wouldn't break any old programs, or thought it would increase
the obscurity level of c++.  As I said: This is consistent with
other features already found in the language!

    Niklas
--
Niklas Hallqvist Phone: +46-(0)31-40 75 00
Applitron Datasystem Fax:   +46-(0)31-83 39 50
Molndalsvagen 95 Email: niklas@appli.se
S-412 63  GOTEBORG, Sweden     mcsun!sunic!chalmers!appli!niklas