6 * \brief The \c begin operation.
8 * Copyright (c) 2009, Marco Guazzone
10 * Distributed under the Boost Software License, Version 1.0. (See
11 * accompanying file LICENSE_1_0.txt or copy at
12 * http://www.boost.org/LICENSE_1_0.txt)
14 * \author Marco Guazzone, marco.guazzone@gmail.com
17 #ifndef BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP
18 #define BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP
21 #include <boost/numeric/ublas/expression_types.hpp>
22 #include <boost/numeric/ublas/fwd.hpp>
23 #include <boost/numeric/ublas/traits/const_iterator_type.hpp>
24 #include <boost/numeric/ublas/traits/iterator_type.hpp>
27 namespace boost { namespace numeric { namespace ublas {
32 * \brief Auxiliary class for implementing the \c begin operation.
33 * \tparam CategoryT The expression category type (e.g., vector_tag).
34 * \tparam TagT The dimension type tag (e.g., tag::major).
35 * \tparam OrientationT The orientation category type (e.g., row_major_tag).
37 template <typename CategoryT, typename TagT=void, typename OrientationT=void>
41 /// \brief Specialization of \c begin_impl for iterating vector expressions.
43 struct begin_impl<vector_tag,void,void>
46 * \brief Return an iterator to the first element of the given vector
48 * \tparam ExprT A model of VectorExpression type.
49 * \param e A vector expression.
50 * \return An iterator over the given vector expression.
52 template <typename ExprT>
53 static typename ExprT::iterator apply(ExprT& e)
60 * \brief Return a const iterator to the first element of the given vector
62 * \tparam ExprT A model of VectorExpression type.
63 * \param e A vector expression.
64 * \return A const iterator to the first element of the given vector
67 template <typename ExprT>
68 static typename ExprT::const_iterator apply(ExprT const& e)
75 /// \brief Specialization of \c begin_impl for iterating matrix expressions with
76 /// a row-major orientation over the major dimension.
78 struct begin_impl<matrix_tag,tag::major,row_major_tag>
81 * \brief Return an iterator to the first element of the given row-major
82 * matrix expression over the major dimension.
83 * \tparam ExprT A model of MatrixExpression type.
84 * \param e A matrix expression.
85 * \return An iterator over the major dimension of the given matrix
88 template <typename ExprT>
89 static typename ExprT::iterator1 apply(ExprT& e)
96 * \brief Return a const iterator to the first element of the given
97 * row-major matrix expression over the major dimension.
98 * \tparam ExprT A model of MatrixExpression type.
99 * \param e A matrix expression.
100 * \return A const iterator over the major dimension of the given matrix
103 template <typename ExprT>
104 static typename ExprT::const_iterator1 apply(ExprT const& e)
111 /// \brief Specialization of \c begin_impl for iterating matrix expressions with
112 /// a column-major orientation over the major dimension.
114 struct begin_impl<matrix_tag,tag::major,column_major_tag>
117 * \brief Return an iterator to the first element of the given column-major
118 * matrix expression over the major dimension.
119 * \tparam ExprT A model of MatrixExpression type.
120 * \param e A matrix expression.
121 * \return An iterator over the major dimension of the given matrix
124 template <typename ExprT>
125 static typename ExprT::iterator2 apply(ExprT& e)
132 * \brief Return a const iterator to the first element of the given
133 * column-major matrix expression over the major dimension.
134 * \tparam ExprT A model of MatrixExpression type.
135 * \param e A matrix expression.
136 * \return A const iterator over the major dimension of the given matrix
139 template <typename ExprT>
140 static typename ExprT::const_iterator2 apply(ExprT const& e)
147 /// \brief Specialization of \c begin_impl for iterating matrix expressions with
148 /// a row-major orientation over the minor dimension.
150 struct begin_impl<matrix_tag,tag::minor,row_major_tag>
153 * \brief Return an iterator to the first element of the given row-major
154 * matrix expression over the minor dimension.
155 * \tparam ExprT A model of MatrixExpression type.
156 * \param e A matrix expression.
157 * \return An iterator over the minor dimension of the given matrix
160 template <typename ExprT>
161 static typename ExprT::iterator2 apply(ExprT& e)
168 * \brief Return a const iterator to the first element of the given
169 * row-major matrix expression over the minor dimension.
170 * \tparam ExprT A model of MatrixExpression type.
171 * \param e A matrix expression.
172 * \return A const iterator over the minor dimension of the given matrix
175 template <typename ExprT>
176 static typename ExprT::const_iterator2 apply(ExprT const& e)
184 /// \brief Specialization of \c begin_impl for iterating matrix expressions with
185 /// a column-major orientation over the minor dimension.
187 struct begin_impl<matrix_tag,tag::minor,column_major_tag>
190 * \brief Return an iterator to the first element of the given column-major
191 * matrix expression over the minor dimension.
192 * \tparam ExprT A model of MatrixExpression type.
193 * \param e A matrix expression.
194 * \return An iterator over the minor dimension of the given matrix
197 template <typename ExprT>
198 static typename ExprT::iterator1 apply(ExprT& e)
205 * \brief Return a const iterator to the first element of the given
206 * column-major matrix expression over the minor dimension.
207 * \tparam ExprT A model of MatrixExpression type.
208 * \param e A matrix expression.
209 * \return A const iterator over the minor dimension of the given matrix
212 template <typename ExprT>
213 static typename ExprT::const_iterator1 apply(ExprT const& e)
219 } // Namespace detail
223 * \brief An iterator to the first element of the given vector expression.
224 * \tparam ExprT A model of VectorExpression type.
225 * \param e A vector expression.
226 * \return An iterator to the first element of the given vector expression.
228 template <typename ExprT>
230 typename ExprT::iterator begin(vector_expression<ExprT>& e)
232 return detail::begin_impl<typename ExprT::type_category>::apply(e());
237 * \brief A const iterator to the first element of the given vector expression.
238 * \tparam ExprT A model of VectorExpression type.
239 * \param e A vector expression.
240 * \return A const iterator to the first element of the given vector expression.
242 template <typename ExprT>
244 typename ExprT::const_iterator begin(vector_expression<ExprT> const& e)
246 return detail::begin_impl<typename ExprT::type_category>::apply(e());
251 * \brief An iterator to the first element of the given matrix expression
252 * according to its orientation.
253 * \tparam DimTagT A dimension tag type (e.g., tag::major).
254 * \tparam ExprT A model of MatrixExpression type.
255 * \param e A matrix expression.
256 * \return An iterator to the first element of the given matrix expression
257 * according to its orientation.
259 template <typename TagT, typename ExprT>
261 typename iterator_type<ExprT,TagT>::type begin(matrix_expression<ExprT>& e)
263 return detail::begin_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
268 * \brief A const iterator to the first element of the given matrix expression
269 * according to its orientation.
270 * \tparam TagT A dimension tag type (e.g., tag::major).
271 * \tparam ExprT A model of MatrixExpression type.
272 * \param e A matrix expression.
273 * \return A const iterator to the first element of the given matrix expression
274 * according to its orientation.
276 template <typename TagT, typename ExprT>
278 typename const_iterator_type<ExprT,TagT>::type begin(matrix_expression<ExprT> const& e)
280 return detail::begin_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
285 * \brief An iterator to the first element over the dual dimension of the given
287 * \tparam IteratorT A model of Iterator type.
288 * \param it An iterator.
289 * \return An iterator to the first element over the dual dimension of the given
292 template <typename IteratorT>
294 typename IteratorT::dual_iterator_type begin(IteratorT& it)
301 * \brief A const iterator to the first element over the dual dimension of the
303 * \tparam IteratorT A model of Iterator type.
304 * \param it An iterator.
305 * \return A const iterator to the first element over the dual dimension of the
308 template <typename IteratorT>
310 typename IteratorT::dual_iterator_type begin(IteratorT const& it)
315 }}} // Namespace boost::numeric::ublas
318 #endif // BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP