Hi all,
I am currently studying data structures and algorithms and I'm
implementing them in C++ purely for fun. I've written a stack
containers that allows to set the internal container at compile time.
The stack template class looks as follows:
template <
typename T,
std::size_t C = 256,
typename TS = array <T, C>
>
class stack {
public:
typedef T data_type;
typedef T* ptr_data_type;
typedef T& ref_data_type;
stack ()
: container_ ()
{ }
stack (const std::size_t size)
: container_ (size)
{ }
// More methods (pop, push, size, capacity)
private:
TS container_;
};
This works perfectly (btw array is another template I created that is
used as default and just wraps an regular array in a class).
When I however want to instantiate this class using a vector I have to
repeat the datatype twice:
#include <vector>
#include "stack.hpp"
int main (int argc, char** argv)
{
stack <int, 256> s1;
stack <int, 256, typename std::vector<int> > s2;
return 0;
}
The first definition (s1) uses the default container. In the second I
use a vector as container. My question... Can I do something so I
don't have to repeat the int type? That way I can't accidently define
the container with another type and the type stored in the stack.
I've been looking in some C++ books, but I can't find a definitive
answer (or I'm looking for the wrong thing).
Thanks in advance,
Kind regards,
Roel.
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|