I suppose there is only one solution then. That is to add another template argument (maybe a couple because of other things I will be using the class for). Here's what I came up with (I'm not sure if my modification a good).
I also discovered that instantiating a template like this does not seems to be possible.Code:template<int N, typename expr1, typename expr2 = expr1, int I = 0, int Stride = 1> class VecOps { enum { loopflag = (I < N-1) ? 1 : 0 }; typedef typename expr1::iterator iterator; typedef typename expr1::const_iterator const_iterator; typedef typename expr1::value_type value_type; typedef VecOps<loopflag*N, expr1, expr2, loopflag*(I+N)> Next; public: static inline void Zero(iterator v) { v[I] = value_type(); Next::Zero(v); } }; template<typename expr1> class VecOps<0, expr1> { typedef typename expr1::iterator iterator; typedef typename expr1::const_iterator const_iterator; typedef typename expr1::value_type value_type; public: static inline void Zero(iterator v) { } }; template<class T, std::size_t dims> class Vector { public: //exactly the same a boosts array class definitions typedef T value_type; typedef T* iterator; typedef const T* const_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef T& reference; typedef const T& const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; private: value_type v[dims]; typedef VecOps<dims, Vector> Ops; public: Vector() { Ops::Zero(begin()); } iterator begin() { return &v[0]; } iterator end() { return &v[dims-1]; } }; int main(int argc, char *argv[]) { Vector<int, 3> v; return EXIT_SUCCESS; }
VecOps<3>::Zero<Vector>(...);
Is there any reason why this is illegal?




Reply With Quote