Chris@16: /** Chris@16: * -*- c++ -*- Chris@16: * Chris@16: * \file begin.hpp Chris@16: * Chris@16: * \brief The \c begin operation. Chris@16: * Chris@16: * Copyright (c) 2009, Marco Guazzone Chris@16: * Chris@16: * Distributed under the Boost Software License, Version 1.0. (See Chris@16: * accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Chris@16: * \author Marco Guazzone, marco.guazzone@gmail.com Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP Chris@16: #define BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { namespace numeric { namespace ublas { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: /** Chris@16: * \brief Auxiliary class for implementing the \c begin operation. Chris@16: * \tparam CategoryT The expression category type (e.g., vector_tag). Chris@16: * \tparam TagT The dimension type tag (e.g., tag::major). Chris@16: * \tparam OrientationT The orientation category type (e.g., row_major_tag). Chris@16: */ Chris@16: template Chris@16: struct begin_impl; Chris@16: Chris@16: Chris@16: /// \brief Specialization of \c begin_impl for iterating vector expressions. Chris@16: template <> Chris@16: struct begin_impl Chris@16: { Chris@16: /** Chris@16: * \brief Return an iterator to the first element of the given vector Chris@16: * expression. Chris@16: * \tparam ExprT A model of VectorExpression type. Chris@16: * \param e A vector expression. Chris@16: * \return An iterator over the given vector expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::iterator apply(ExprT& e) Chris@16: { Chris@16: return e.begin(); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief Return a const iterator to the first element of the given vector Chris@16: * expression. Chris@16: * \tparam ExprT A model of VectorExpression type. Chris@16: * \param e A vector expression. Chris@16: * \return A const iterator to the first element of the given vector Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::const_iterator apply(ExprT const& e) Chris@16: { Chris@16: return e.begin(); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: /// \brief Specialization of \c begin_impl for iterating matrix expressions with Chris@16: /// a row-major orientation over the major dimension. Chris@16: template <> Chris@16: struct begin_impl Chris@16: { Chris@16: /** Chris@16: * \brief Return an iterator to the first element of the given row-major Chris@16: * matrix expression over the major dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return An iterator over the major dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::iterator1 apply(ExprT& e) Chris@16: { Chris@16: return e.begin1(); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief Return a const iterator to the first element of the given Chris@16: * row-major matrix expression over the major dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return A const iterator over the major dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::const_iterator1 apply(ExprT const& e) Chris@16: { Chris@16: return e.begin1(); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: /// \brief Specialization of \c begin_impl for iterating matrix expressions with Chris@16: /// a column-major orientation over the major dimension. Chris@16: template <> Chris@16: struct begin_impl Chris@16: { Chris@16: /** Chris@16: * \brief Return an iterator to the first element of the given column-major Chris@16: * matrix expression over the major dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return An iterator over the major dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::iterator2 apply(ExprT& e) Chris@16: { Chris@16: return e.begin2(); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief Return a const iterator to the first element of the given Chris@16: * column-major matrix expression over the major dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return A const iterator over the major dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::const_iterator2 apply(ExprT const& e) Chris@16: { Chris@16: return e.begin2(); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: /// \brief Specialization of \c begin_impl for iterating matrix expressions with Chris@16: /// a row-major orientation over the minor dimension. Chris@16: template <> Chris@16: struct begin_impl Chris@16: { Chris@16: /** Chris@16: * \brief Return an iterator to the first element of the given row-major Chris@16: * matrix expression over the minor dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return An iterator over the minor dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::iterator2 apply(ExprT& e) Chris@16: { Chris@16: return e.begin2(); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief Return a const iterator to the first element of the given Chris@16: * row-major matrix expression over the minor dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return A const iterator over the minor dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::const_iterator2 apply(ExprT const& e) Chris@16: { Chris@16: return e.begin2(); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: /// \brief Specialization of \c begin_impl for iterating matrix expressions with Chris@16: /// a column-major orientation over the minor dimension. Chris@16: template <> Chris@16: struct begin_impl Chris@16: { Chris@16: /** Chris@16: * \brief Return an iterator to the first element of the given column-major Chris@16: * matrix expression over the minor dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return An iterator over the minor dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::iterator1 apply(ExprT& e) Chris@16: { Chris@16: return e.begin1(); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief Return a const iterator to the first element of the given Chris@16: * column-major matrix expression over the minor dimension. Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return A const iterator over the minor dimension of the given matrix Chris@16: * expression. Chris@16: */ Chris@16: template Chris@16: static typename ExprT::const_iterator1 apply(ExprT const& e) Chris@16: { Chris@16: return e.begin1(); Chris@16: } Chris@16: }; Chris@16: Chris@16: } // Namespace detail Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief An iterator to the first element of the given vector expression. Chris@16: * \tparam ExprT A model of VectorExpression type. Chris@16: * \param e A vector expression. Chris@16: * \return An iterator to the first element of the given vector expression. Chris@16: */ Chris@16: template Chris@16: BOOST_UBLAS_INLINE Chris@16: typename ExprT::iterator begin(vector_expression& e) Chris@16: { Chris@16: return detail::begin_impl::apply(e()); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief A const iterator to the first element of the given vector expression. Chris@16: * \tparam ExprT A model of VectorExpression type. Chris@16: * \param e A vector expression. Chris@16: * \return A const iterator to the first element of the given vector expression. Chris@16: */ Chris@16: template Chris@16: BOOST_UBLAS_INLINE Chris@16: typename ExprT::const_iterator begin(vector_expression const& e) Chris@16: { Chris@16: return detail::begin_impl::apply(e()); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief An iterator to the first element of the given matrix expression Chris@16: * according to its orientation. Chris@16: * \tparam DimTagT A dimension tag type (e.g., tag::major). Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return An iterator to the first element of the given matrix expression Chris@16: * according to its orientation. Chris@16: */ Chris@16: template Chris@16: BOOST_UBLAS_INLINE Chris@16: typename iterator_type::type begin(matrix_expression& e) Chris@16: { Chris@16: return detail::begin_impl::apply(e()); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief A const iterator to the first element of the given matrix expression Chris@16: * according to its orientation. Chris@16: * \tparam TagT A dimension tag type (e.g., tag::major). Chris@16: * \tparam ExprT A model of MatrixExpression type. Chris@16: * \param e A matrix expression. Chris@16: * \return A const iterator to the first element of the given matrix expression Chris@16: * according to its orientation. Chris@16: */ Chris@16: template Chris@16: BOOST_UBLAS_INLINE Chris@16: typename const_iterator_type::type begin(matrix_expression const& e) Chris@16: { Chris@16: return detail::begin_impl::apply(e()); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief An iterator to the first element over the dual dimension of the given Chris@16: * iterator. Chris@16: * \tparam IteratorT A model of Iterator type. Chris@16: * \param it An iterator. Chris@16: * \return An iterator to the first element over the dual dimension of the given Chris@16: * iterator. Chris@16: */ Chris@16: template Chris@16: BOOST_UBLAS_INLINE Chris@16: typename IteratorT::dual_iterator_type begin(IteratorT& it) Chris@16: { Chris@16: return it.begin(); Chris@16: } Chris@16: Chris@16: Chris@16: /** Chris@16: * \brief A const iterator to the first element over the dual dimension of the Chris@16: * given iterator. Chris@16: * \tparam IteratorT A model of Iterator type. Chris@16: * \param it An iterator. Chris@16: * \return A const iterator to the first element over the dual dimension of the Chris@16: * given iterator. Chris@16: */ Chris@16: template Chris@16: BOOST_UBLAS_INLINE Chris@16: typename IteratorT::dual_iterator_type begin(IteratorT const& it) Chris@16: { Chris@16: return it.begin(); Chris@16: } Chris@16: Chris@16: }}} // Namespace boost::numeric::ublas Chris@16: Chris@16: Chris@16: #endif // BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP