#ifndef glas_sparse_dense_view_hpp #define glas_sparse_dense_view_hpp #include #include #include #include namespace glas { // dense_view for a SparseVectorExpression template class sparse_dense_view { public: typedef typename SparseVectorExpression::nnz_type size_type ; // VectorExpression typedef typename SparseVectorExpression::value_type value_type ; // VectorExpression typedef typename SparseVectorExpression::const_nz_reference const_reference ; // VectorExpression typedef typename boost::mpl::if_< is_vector_collection< SparseVectorExpression >, typename boost::mpl::if_< boost::is_const< SparseVectorExpression >, typename SparseVectorExpression::const_nz_reference, typename SparseVectorExpression::nz_reference >::type, const_reference >::type reference ; // Collection typedef SparseVectorExpression source_type ; // typedef typename boost::add_const::type const_source_type ; typedef boost::mpl::vector< dense_vector_expression_concept > concept_type ; public: /// requirement of View sparse_dense_view( source_type& s ) : source_( s ) {} /// requirement of Assignable sparse_dense_view( sparse_dense_view const& v ) : source_( v.source_ ) {} /// requirement of Assignable sparse_dense_view& operator=( sparse_dense_view const& v ) { // Call assign function return *this ; } /// requirement of EqualityComparable bool operator==(sparse_dense_view const & that) { size_type size = size() ; for(size_type i = 0 ; i < size ; ++i ) if ( that[i] != (*this)[i] ) return false ; return true ; } /// requirement of EqualityComparable bool operator!=(sparse_dense_view const & that) { return !((*this)==that) ; } /// requirement of VectorExpression size_type size() const { return source_.nnz() ; } /// requirement of VectorExpression const_reference operator[]( size_type i ) const { return source_.nz(i) ; } /// requirement of VectorCollection reference operator[]( size_type i ) { return source_.nz(i) ; } /// requirement of VectorExpression const_reference operator()( size_type i ) const { return source_.nz(i) ; } /// requirement of VectorCollection reference operator()( size_type i ) { return source_.nz(i) ; } /// required by View source_type& source() { return source_ ; } public: source_type& source_ ; } ; } #endif