aboutsummaryrefslogtreecommitdiffstats
path: root/models/vecn.hpp
blob: 4dc96eb985901ca0c823519f7a278abbfc3b83dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
   \file vecn.hpp
   \brief n-dim fixed size vector
   \author Junhua Gu
 */


#ifndef VECN_HPP
#define VECN_HPP
#define OPT_HEADER
#include <iostream>
namespace opt_utilities
{
  template <typename T,int n>
  class vecn
  {
  public:
    T data[n];
  public:
    T& operator[](int i)
    {
      return data[i];
    }
    
    const T& operator[](int i)const
    {
      return data[i];
    }
    
    vecn()
    {
      for(int i=0;i<n;++i)
	{
	  data[i]=0;
	}
    }
    
  };

  template <typename T,int n>
  std::istream& operator>>(std::istream& is,vecn<T,n>& p)
  {
    for(int i=0;i<n;++i)
      {
	is>>p[i];
	//	std::cout<<i<<std::endl;
      }
    return is;
  }


  template <typename T,int n>
  std::ostream& operator<<(std::ostream& os,const vecn<T,n>& p)
  {
    os<<'[';
    for(int i=0;i<n;++i)
      {
	os<<p[i]<<",";
	//	std::cout<<i<<std::endl;
      }
    os<<']';
    return os;
  }
}

#endif
//EOF