scalar_seq_view.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_META_SCALAR_SEQ_VIEW_HPP
2 #define STAN_MATH_PRIM_SCAL_META_SCALAR_SEQ_VIEW_HPP
3 
5 
6 namespace stan {
7 /**
8  * scalar_seq_view provides a uniform sequence-like wrapper around either a
9  * scalar or a sequence of scalars.
10  *
11  * @tparam C the container type; will be the scalar type if wrapping a scalar
12  * @tparam T the scalar type
13  */
16  public:
17  explicit scalar_seq_view(const C& c) : c_(c) {}
18 
19  /**
20  * Segfaults if out of bounds.
21  * @param i index
22  * @return the element at the specified position in the container
23  */
24  const T& operator[](int i) const { return c_[i]; }
25 
26  int size() const { return c_.size(); }
27 
28  private:
29  const C& c_;
30 };
31 
32 /**
33  * This specialization handles wrapping a scalar as if it were a sequence.
34  *
35  * @tparam T the scalar type
36  */
37 template <typename T>
38 class scalar_seq_view<T, T> {
39  public:
40  explicit scalar_seq_view(const T& t) : t_(t) {}
41 
42  const T& operator[](int /* i */) const { return t_; }
43 
44  int size() const { return 1; }
45 
46  private:
47  const T& t_;
48 };
49 } // namespace stan
50 #endif
const double C
const T & operator[](int i) const
double T
Definition: Xdiff_gwt.C:5
const T & operator[](int) const