6 * \brief The \c end 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
18 #ifndef BOOST_NUMERIC_UBLAS_OPERATION_END_HPP
19 #define BOOST_NUMERIC_UBLAS_OPERATION_END_HPP
22 #include <boost/numeric/ublas/expression_types.hpp>
23 #include <boost/numeric/ublas/fwd.hpp>
24 #include <boost/numeric/ublas/traits/const_iterator_type.hpp>
25 #include <boost/numeric/ublas/traits/iterator_type.hpp>
28 namespace boost { namespace numeric { namespace ublas {
33 * \brief Auxiliary class for implementing the \c end operation.
34 * \tparam CategoryT The expression category type (e.g., vector_tag).
35 * \tparam TagT The dimension type tag (e.g., tag::major).
36 * \tparam OrientationT The orientation category type (e.g., row_major_tag).
38 template <typename CategoryT, typename TagT=void, typename OrientationT=void>
42 /// \brief Specialization of \c end_impl for iterating vector expressions.
44 struct end_impl<vector_tag,void,void>
47 * \brief Return an iterator to the last element of the given vector
49 * \tparam ExprT A model of VectorExpression type.
50 * \param e A vector expression.
51 * \return An iterator over the given vector expression.
53 template <typename ExprT>
54 static typename ExprT::iterator apply(ExprT& e)
61 * \brief Return a const iterator to the last element of the given vector
63 * \tparam ExprT A model of VectorExpression type.
64 * \param e A vector expression.
65 * \return A const iterator to the first element of the given vector
68 template <typename ExprT>
69 static typename ExprT::const_iterator apply(ExprT const& e)
76 /// \brief Specialization of \c end_impl for iterating matrix expressions with a
77 /// row-major orientation over the major dimension.
79 struct end_impl<matrix_tag,tag::major,row_major_tag>
82 * \brief Return an iterator to the last element of the given row-major
83 * matrix expression over the major dimension.
84 * \tparam ExprT A model of MatrixExpression type.
85 * \param e A matrix expression.
86 * \return An iterator over the major dimension of the given matrix
89 template <typename ExprT>
90 static typename ExprT::iterator1 apply(ExprT& e)
97 * \brief Return a const iterator to the last element of the given row-major
98 * matrix expression over the major dimension.
99 * \tparam ExprT A model of MatrixExpression type.
100 * \param e A matrix expression.
101 * \return A const iterator over the major dimension of the given matrix
104 template <typename ExprT>
105 static typename ExprT::const_iterator1 apply(ExprT const& e)
112 /// \brief Specialization of \c end_impl for iterating matrix expressions with a
113 /// column-major orientation over the major dimension.
115 struct end_impl<matrix_tag,tag::major,column_major_tag>
118 * \brief Return an iterator to the last element of the given column-major
119 * matrix expression over the major dimension.
120 * \tparam ExprT A model of MatrixExpression type.
121 * \param e A matrix expression.
122 * \return An iterator over the major dimension of the given matrix
125 template <typename ExprT>
126 static typename ExprT::iterator2 apply(ExprT& e)
133 * \brief Return a const iterator to the last element of the given
134 * column-major matrix expression over the major dimension.
135 * \tparam ExprT A model of MatrixExpression type.
136 * \param e A matrix expression.
137 * \return A const iterator over the major dimension of the given matrix
140 template <typename ExprT>
141 static typename ExprT::const_iterator2 apply(ExprT const& e)
148 /// \brief Specialization of \c end_impl for iterating matrix expressions with a
149 /// row-major orientation over the minor dimension.
151 struct end_impl<matrix_tag,tag::minor,row_major_tag>
154 * \brief Return an iterator to the last element of the given row-major
155 * matrix expression over the minor dimension.
156 * \tparam ExprT A model of MatrixExpression type.
157 * \param e A matrix expression.
158 * \return An iterator over the minor dimension of the given matrix
161 template <typename ExprT>
162 static typename ExprT::iterator2 apply(ExprT& e)
169 * \brief Return a const iterator to the last element of the given
170 * row-minor matrix expression over the major dimension.
171 * \tparam ExprT A model of MatrixExpression type.
172 * \param e A matrix expression.
173 * \return A const iterator over the minor dimension of the given matrix
176 template <typename ExprT>
177 static typename ExprT::const_iterator2 apply(ExprT const& e)
184 /// \brief Specialization of \c end_impl for iterating matrix expressions with a
185 /// column-major orientation over the minor dimension.
187 struct end_impl<matrix_tag,tag::minor,column_major_tag>
190 * \brief Return an iterator to the last 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 last element of the given
206 * column-minor matrix expression over the major 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 last 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 last element of the given vector expression.
228 template <typename ExprT>
230 typename ExprT::iterator end(vector_expression<ExprT>& e)
232 return detail::end_impl<typename ExprT::type_category>::apply(e());
237 * \brief A const iterator to the last 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 last element of the given vector expression.
242 template <typename ExprT>
244 typename ExprT::const_iterator end(vector_expression<ExprT> const& e)
246 return detail::end_impl<typename ExprT::type_category>::apply(e());
251 * \brief An iterator to the last 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 last element of the given matrix expression
257 * according to its orientation.
259 template <typename TagT, typename ExprT>
261 typename iterator_type<ExprT,TagT>::type end(matrix_expression<ExprT>& e)
263 return detail::end_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
268 * \brief A const iterator to the last 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 last 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 end(matrix_expression<ExprT> const& e)
280 return detail::end_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
285 * \brief An iterator to the last 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 last element over the dual dimension of the given
292 template <typename IteratorT>
294 typename IteratorT::dual_iterator_type end(IteratorT& it)
301 * \brief A const iterator to the last 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 last element over the dual dimension of the
308 template <typename IteratorT>
310 typename IteratorT::dual_iterator_type end(IteratorT const& it)
315 }}} // Namespace boost::numeric::ublas
318 #endif // BOOST_NUMERIC_UBLAS_OPERATION_END_HPP