aboutsummaryrefslogtreecommitdiffstats
path: root/core/opt_traits.hpp
blob: b8426e02f79b7f327084b89b57fc366bb9b1c05b (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
#ifndef ARRAY_OPERATION
#define ARRAY_OPERATION
#include <cstddef>
namespace opt_utilities
{
  /////////Useful function///////////////////////////////////
  template <typename T>
  inline size_t get_size(const T& x)
  {
    return x.size();
  }
  
  template <typename T>
  class element_type_trait
  {
  public:
    typedef typename T::value_type element_type;
  };

  template <typename T>
  class return_type_trait
  {
  public:
    typedef T value_type;
    typedef T& reference_type;
    typedef const T& const_reference_type;
  };
  
  template <typename T>
  inline typename 
  return_type_trait<typename element_type_trait<T>::element_type>::
  const_reference_type get_element(const T& x,size_t i)
  {
    return x[i];
  }
  /*
  template <typename T>
  inline typename element_type_trait<T>::element_type& get_element(T& x,size_t i)
  {
    return x[i];
  }
  */

  template<typename T,typename TX>
  inline void set_element(T& x,size_t i,
			  const TX& v)
  {
    x[i]=v;
  }

  template <typename T>
  inline void resize(T& x,size_t s)
  {
    x.resize(s);
  }

  template <typename Tl,typename Tr>
  inline Tl& opt_eq(Tl& lhs,const Tr& rhs)
  {
    return (lhs=rhs);
  }
}



#endif