|
||||
File indexing completed on 2025-01-18 09:43:01
0001 /** 0002 * -*- c++ -*- 0003 * 0004 * \file begin.hpp 0005 * 0006 * \brief The \c begin operation. 0007 * 0008 * Copyright (c) 2009, Marco Guazzone 0009 * 0010 * Distributed under the Boost Software License, Version 1.0. (See 0011 * accompanying file LICENSE_1_0.txt or copy at 0012 * http://www.boost.org/LICENSE_1_0.txt) 0013 * 0014 * \author Marco Guazzone, marco.guazzone@gmail.com 0015 */ 0016 0017 #ifndef BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP 0018 #define BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP 0019 0020 0021 #include <boost/numeric/ublas/expression_types.hpp> 0022 #include <boost/numeric/ublas/fwd.hpp> 0023 #include <boost/numeric/ublas/traits/const_iterator_type.hpp> 0024 #include <boost/numeric/ublas/traits/iterator_type.hpp> 0025 0026 0027 namespace boost { namespace numeric { namespace ublas { 0028 0029 namespace detail { 0030 0031 /** 0032 * \brief Auxiliary class for implementing the \c begin operation. 0033 * \tparam CategoryT The expression category type (e.g., vector_tag). 0034 * \tparam TagT The dimension type tag (e.g., tag::major). 0035 * \tparam OrientationT The orientation category type (e.g., row_major_tag). 0036 */ 0037 template <typename CategoryT, typename TagT=void, typename OrientationT=void> 0038 struct begin_impl; 0039 0040 0041 /// \brief Specialization of \c begin_impl for iterating vector expressions. 0042 template <> 0043 struct begin_impl<vector_tag,void,void> 0044 { 0045 /** 0046 * \brief Return an iterator to the first element of the given vector 0047 * expression. 0048 * \tparam ExprT A model of VectorExpression type. 0049 * \param e A vector expression. 0050 * \return An iterator over the given vector expression. 0051 */ 0052 template <typename ExprT> 0053 static typename ExprT::iterator apply(ExprT& e) 0054 { 0055 return e.begin(); 0056 } 0057 0058 0059 /** 0060 * \brief Return a const iterator to the first element of the given vector 0061 * expression. 0062 * \tparam ExprT A model of VectorExpression type. 0063 * \param e A vector expression. 0064 * \return A const iterator to the first element of the given vector 0065 * expression. 0066 */ 0067 template <typename ExprT> 0068 static typename ExprT::const_iterator apply(ExprT const& e) 0069 { 0070 return e.begin(); 0071 } 0072 }; 0073 0074 0075 /// \brief Specialization of \c begin_impl for iterating matrix expressions with 0076 /// a row-major orientation over the major dimension. 0077 template <> 0078 struct begin_impl<matrix_tag,tag::major,row_major_tag> 0079 { 0080 /** 0081 * \brief Return an iterator to the first element of the given row-major 0082 * matrix expression over the major dimension. 0083 * \tparam ExprT A model of MatrixExpression type. 0084 * \param e A matrix expression. 0085 * \return An iterator over the major dimension of the given matrix 0086 * expression. 0087 */ 0088 template <typename ExprT> 0089 static typename ExprT::iterator1 apply(ExprT& e) 0090 { 0091 return e.begin1(); 0092 } 0093 0094 0095 /** 0096 * \brief Return a const iterator to the first element of the given 0097 * row-major matrix expression over the major dimension. 0098 * \tparam ExprT A model of MatrixExpression type. 0099 * \param e A matrix expression. 0100 * \return A const iterator over the major dimension of the given matrix 0101 * expression. 0102 */ 0103 template <typename ExprT> 0104 static typename ExprT::const_iterator1 apply(ExprT const& e) 0105 { 0106 return e.begin1(); 0107 } 0108 }; 0109 0110 0111 /// \brief Specialization of \c begin_impl for iterating matrix expressions with 0112 /// a column-major orientation over the major dimension. 0113 template <> 0114 struct begin_impl<matrix_tag,tag::major,column_major_tag> 0115 { 0116 /** 0117 * \brief Return an iterator to the first element of the given column-major 0118 * matrix expression over the major dimension. 0119 * \tparam ExprT A model of MatrixExpression type. 0120 * \param e A matrix expression. 0121 * \return An iterator over the major dimension of the given matrix 0122 * expression. 0123 */ 0124 template <typename ExprT> 0125 static typename ExprT::iterator2 apply(ExprT& e) 0126 { 0127 return e.begin2(); 0128 } 0129 0130 0131 /** 0132 * \brief Return a const iterator to the first element of the given 0133 * column-major matrix expression over the major dimension. 0134 * \tparam ExprT A model of MatrixExpression type. 0135 * \param e A matrix expression. 0136 * \return A const iterator over the major dimension of the given matrix 0137 * expression. 0138 */ 0139 template <typename ExprT> 0140 static typename ExprT::const_iterator2 apply(ExprT const& e) 0141 { 0142 return e.begin2(); 0143 } 0144 }; 0145 0146 0147 /// \brief Specialization of \c begin_impl for iterating matrix expressions with 0148 /// a row-major orientation over the minor dimension. 0149 template <> 0150 struct begin_impl<matrix_tag,tag::minor,row_major_tag> 0151 { 0152 /** 0153 * \brief Return an iterator to the first element of the given row-major 0154 * matrix expression over the minor dimension. 0155 * \tparam ExprT A model of MatrixExpression type. 0156 * \param e A matrix expression. 0157 * \return An iterator over the minor dimension of the given matrix 0158 * expression. 0159 */ 0160 template <typename ExprT> 0161 static typename ExprT::iterator2 apply(ExprT& e) 0162 { 0163 return e.begin2(); 0164 } 0165 0166 0167 /** 0168 * \brief Return a const iterator to the first element of the given 0169 * row-major matrix expression over the minor dimension. 0170 * \tparam ExprT A model of MatrixExpression type. 0171 * \param e A matrix expression. 0172 * \return A const iterator over the minor dimension of the given matrix 0173 * expression. 0174 */ 0175 template <typename ExprT> 0176 static typename ExprT::const_iterator2 apply(ExprT const& e) 0177 { 0178 return e.begin2(); 0179 } 0180 }; 0181 0182 0183 0184 /// \brief Specialization of \c begin_impl for iterating matrix expressions with 0185 /// a column-major orientation over the minor dimension. 0186 template <> 0187 struct begin_impl<matrix_tag,tag::minor,column_major_tag> 0188 { 0189 /** 0190 * \brief Return an iterator to the first element of the given column-major 0191 * matrix expression over the minor dimension. 0192 * \tparam ExprT A model of MatrixExpression type. 0193 * \param e A matrix expression. 0194 * \return An iterator over the minor dimension of the given matrix 0195 * expression. 0196 */ 0197 template <typename ExprT> 0198 static typename ExprT::iterator1 apply(ExprT& e) 0199 { 0200 return e.begin1(); 0201 } 0202 0203 0204 /** 0205 * \brief Return a const iterator to the first element of the given 0206 * column-major matrix expression over the minor dimension. 0207 * \tparam ExprT A model of MatrixExpression type. 0208 * \param e A matrix expression. 0209 * \return A const iterator over the minor dimension of the given matrix 0210 * expression. 0211 */ 0212 template <typename ExprT> 0213 static typename ExprT::const_iterator1 apply(ExprT const& e) 0214 { 0215 return e.begin1(); 0216 } 0217 }; 0218 0219 } // Namespace detail 0220 0221 0222 /** 0223 * \brief An iterator to the first element of the given vector expression. 0224 * \tparam ExprT A model of VectorExpression type. 0225 * \param e A vector expression. 0226 * \return An iterator to the first element of the given vector expression. 0227 */ 0228 template <typename ExprT> 0229 BOOST_UBLAS_INLINE 0230 typename ExprT::iterator begin(vector_expression<ExprT>& e) 0231 { 0232 return detail::begin_impl<typename ExprT::type_category>::apply(e()); 0233 } 0234 0235 0236 /** 0237 * \brief A const iterator to the first element of the given vector expression. 0238 * \tparam ExprT A model of VectorExpression type. 0239 * \param e A vector expression. 0240 * \return A const iterator to the first element of the given vector expression. 0241 */ 0242 template <typename ExprT> 0243 BOOST_UBLAS_INLINE 0244 typename ExprT::const_iterator begin(vector_expression<ExprT> const& e) 0245 { 0246 return detail::begin_impl<typename ExprT::type_category>::apply(e()); 0247 } 0248 0249 0250 /** 0251 * \brief An iterator to the first element of the given matrix expression 0252 * according to its orientation. 0253 * \tparam DimTagT A dimension tag type (e.g., tag::major). 0254 * \tparam ExprT A model of MatrixExpression type. 0255 * \param e A matrix expression. 0256 * \return An iterator to the first element of the given matrix expression 0257 * according to its orientation. 0258 */ 0259 template <typename TagT, typename ExprT> 0260 BOOST_UBLAS_INLINE 0261 typename iterator_type<ExprT,TagT>::type begin(matrix_expression<ExprT>& e) 0262 { 0263 return detail::begin_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e()); 0264 } 0265 0266 0267 /** 0268 * \brief A const iterator to the first element of the given matrix expression 0269 * according to its orientation. 0270 * \tparam TagT A dimension tag type (e.g., tag::major). 0271 * \tparam ExprT A model of MatrixExpression type. 0272 * \param e A matrix expression. 0273 * \return A const iterator to the first element of the given matrix expression 0274 * according to its orientation. 0275 */ 0276 template <typename TagT, typename ExprT> 0277 BOOST_UBLAS_INLINE 0278 typename const_iterator_type<ExprT,TagT>::type begin(matrix_expression<ExprT> const& e) 0279 { 0280 return detail::begin_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e()); 0281 } 0282 0283 0284 /** 0285 * \brief An iterator to the first element over the dual dimension of the given 0286 * iterator. 0287 * \tparam IteratorT A model of Iterator type. 0288 * \param it An iterator. 0289 * \return An iterator to the first element over the dual dimension of the given 0290 * iterator. 0291 */ 0292 template <typename IteratorT> 0293 BOOST_UBLAS_INLINE 0294 typename IteratorT::dual_iterator_type begin(IteratorT& it) 0295 { 0296 return it.begin(); 0297 } 0298 0299 0300 /** 0301 * \brief A const iterator to the first element over the dual dimension of the 0302 * given iterator. 0303 * \tparam IteratorT A model of Iterator type. 0304 * \param it An iterator. 0305 * \return A const iterator to the first element over the dual dimension of the 0306 * given iterator. 0307 */ 0308 template <typename IteratorT> 0309 BOOST_UBLAS_INLINE 0310 typename IteratorT::dual_iterator_type begin(IteratorT const& it) 0311 { 0312 return it.begin(); 0313 } 0314 0315 }}} // Namespace boost::numeric::ublas 0316 0317 0318 #endif // BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |