OK, here's repost with all the modifications McKenzie asked for.
Code:#include <cstdlib> #include <iterator> template<int N, int I = 0, int Stride = 1> class VecOps { enum { loopflag = (I < N-1) ? 1 : 0 }; public: template<class expr> static inline void Zero(typename expr::iterator v) { v[I] = typename expr::value_type(); VecOps<loopflag*N, loopflag*(I+1)>::Zero(v); } }; template<> class VecOps<0> { public: template<class expr> static inline void Zero(typename expr::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]; public: Vector() { VecOps<dims>::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; }




Reply With Quote