Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
VectorViewMvt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_META_VECTORVIEWMVT_HPP
2 #define STAN_MATH_PRIM_SCAL_META_VECTORVIEWMVT_HPP
3 
7 #include <stdexcept>
8 #include <vector>
9 
10 namespace stan {
11 
12  template <typename T, bool is_array
14  <typename stan::math::value_type<T>::type>::value,
15  bool throw_if_accessed = false>
16  class VectorViewMvt {
17  public:
19 
20  explicit VectorViewMvt(matrix_t& m) : x_(&m) { }
21 
22  explicit VectorViewMvt(std::vector<matrix_t>& vm) : x_(&vm[0]) { }
23 
24  matrix_t& operator[](int i) {
25  if (throw_if_accessed)
26  throw std::out_of_range("VectorViewMvt: this cannot be accessed");
27  if (is_array)
28  return x_[i];
29  else
30  return x_[0];
31  }
32  private:
33  matrix_t* x_;
34  };
35 
40  template <typename T, bool is_array, bool throw_if_accessed>
41  class VectorViewMvt<const T, is_array, throw_if_accessed> {
42  public:
44 
45  explicit VectorViewMvt(const matrix_t& m) : x_(&m) { }
46 
47  explicit VectorViewMvt(const std::vector<matrix_t>& vm) : x_(&vm[0]) { }
48 
49  const matrix_t& operator[](int i) const {
50  if (throw_if_accessed)
51  throw std::out_of_range("VectorViewMvt: this cannot be accessed");
52  if (is_array)
53  return x_[i];
54  else
55  return x_[0];
56  }
57  private:
58  const matrix_t* x_;
59  };
60 
61 
62 }
63 #endif
64 
scalar_type_helper_pre< is_vector< typename stan::math::value_type< T >::type >::value, typename stan::math::value_type< T >::type, T >::type type
VectorViewMvt(std::vector< matrix_t > &vm)
matrix_t & operator[](int i)
void out_of_range(const char *function, const int max, const int index, const char *msg1="", const char *msg2="")
Throw an out_of_range exception with a consistently formatted message.
VectorViewMvt(matrix_t &m)
scalar_type_pre< T >::type matrix_t
Primary template class for metaprogram to compute the type of values stored in a container.
Definition: value_type.hpp:21

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