#include<iostream>
#include<string>
#include<cstddef>
#include<functional>
#include<algorithm>
using namespace std;
template<typename T,std::size_t thesize>
class carray{
private:
T v[thesize];
public:
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef T& reference;
typedef const T& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
iterator begin(){
return &v[0];
}
const_iterator begin() const{
return &v[0];
}
iterator end(){
return v+thesize;
}
const_iterator end() const{
return v+thesize;
}
reference operator[](std::size_t i){
return v[i];
}
const_reference operator[](std::size_t i) const{
return v[i];
}
size_type size() const{
return thesize;
}
size_type max_size(){
return thesize;
}
T* as_array(){
return v;
}
};
int main(){
carray<int,10>a;
for(unsigned i=0;i<a.size();++i){
a[i]=i+1;
}
for(unsigned i=0;i<a.size();++i){
cout<<a[i]<<" ";
}
cout<<endl;
reverse(a.begin(),a.end());
for(unsigned j=0;j<a.size();++j){
cout<<a[j]<<" ";
}
cout<<endl;
transform(a.begin(),a.end(),a.begin(),negate<int>());
for(int i=0;i<a.size();++i){
cout<<a[i]<<" ";
}
cout<<endl;
system("pause");
return 0;
}
更详细的资料,参考boost网站的资料:看贴图
模仿,自己写一个容器,有增删改函数、