Stan Math Library  2.11.0
reverse mode automatic differentiation
VectorView.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_ARR_SCAL_META_VECTORVIEW_HPP
2 #define STAN_MATH_ARR_SCAL_META_VECTORVIEW_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8 
9  template <typename T>
10  class VectorView<std::vector<T>, true, false> {
11  public:
12  typedef typename scalar_type<T>::type scalar_t;
13 
14  template <typename X>
15  explicit VectorView(X& x) : x_(&x[0]) { }
16 
17  scalar_t& operator[](int i) {
18  return x_[i];
19  }
20 
21  private:
22  scalar_t* x_;
23  };
24 
25  template <typename T>
26  class VectorView<const std::vector<T>, true, false> {
27  public:
28  typedef typename boost::add_const<typename scalar_type<T>::type>::type
30 
31  template <typename X>
32  explicit VectorView(X& x) : x_(&x[0]) { }
33 
34  scalar_t& operator[](int i) const {
35  return x_[i];
36  }
37  private:
38  scalar_t* x_;
39  };
40 
41 }
42 #endif
boost::conditional< boost::is_const< T >::value, typename boost::add_const< typename scalar_type< T >::type >::type, typename scalar_type< T >::type >::type scalar_t
Definition: VectorView.hpp:54
scalar_type_helper< is_vector< T >::value, T >::type type
Definition: scalar_type.hpp:35
boost::add_const< typename scalar_type< T >::type >::type scalar_t
Definition: VectorView.hpp:29
VectorView is a template expression that is constructed with a container or scalar, which it then allows to be used as an array using operator[].
Definition: VectorView.hpp:48

     [ Stan Home Page ] © 2011–2016, Stan Development Team.