template <typename TYPE>class Array {public: typedef TYPE value_type; typedef int size_type; typedef TYPE const& const_reference; typedef TYPE const* const_iterator; typedef TYPE& reference; typedef TYPE* iterator;public: Array() : _begin(0), _size(0) { } Array(const Array<value_type>& array) : _begin(array._begin), _size(array._size) { } Array(const value_type* ptr, size_type size) : _begin(const_cast<value_type*>(ptr)), _size(size) { } ~Array() { } size_type size() const { return _size; } const_reference operator[](int index) const { return _begin[index]; } const_iterator begin() const { return _begin; } const_iterator end() const { return _begin + _size; } reference operator[](int index) { return _begin[index]; } iterator begin() { return _begin; } iterator end() { return _begin + _size; }protected: value_type* _begin; size_type _size;};
C++ (Qt) int a[] = { 1, 2, 3, 4, 5 }; for( auto it = std::begin( a ); it != std::end( a ); ++it ) cout << *it << endl; return 0;
C++ (Qt)void DoSomething( Type & a ){ for (auto it = std::begin(a)....
C++ (Qt) const int a[] = {1, 2, 3, 4, 5}; Array<int> wrapper(a, 5); wrapper[2] = 7;
typedef Array<int> TIndexArray;void CalcIndexHalfs( TIndexArray & arr ){ size_t half = arr.size() / 2; CalcOne(TIndexArray(&arr[0], half)); CalcTwo(TIndexArray(&arr[half], arr.size() - half));}