<h3>General</h3>
<ol>
+<li> New: It has long been a nuisance that the deal.II vector classes
+could only be accessed using <code>operator()</code> whereas the C++
+<code>std::vector</code> class required <code>operator[]</code>. This
+diminished the usefulness of template code. Historically, the reason
+was that the deal.II vector classes should use the same operator as
+the matrix classes, and C++ does not allow to use <code>operator[]</code>
+for matrices since this operator can only take a single argument.
+<br>
+In any case, all deal.II vector classes now support both kinds of
+access operators interchangeably.
+<br>
+(Wolfgang Bangerth, 2012/02/12)
+
<li> Fixed: Linking shared libraries on PowerPC systems (e.g. on
BlueGene systems) failed due to a miscommunication between compiler
and linker. This is now worked around.
//---------------------------------------------------------------------------
// $Id$
//
-// Copyright (C) 2004, 2005, 2006, 2007, 2010, 2011 by the deal.II authors
+// Copyright (C) 2004, 2005, 2006, 2007, 2010, 2011, 2012 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
*/
reference operator() (const unsigned int i);
+ /**
+ * Access components, returns U(i).
+ *
+ * Exactly the same as operator().
+ */
+ value_type operator[] (const unsigned int i) const;
+
+ /**
+ * Access components, returns U(i)
+ * as a writeable reference.
+ *
+ * Exactly the same as operator().
+ */
+ reference operator[] (const unsigned int i);
+
/**
* Copy operator: fill all components of
* the vector with the given scalar
return components[local_index.first](local_index.second);
}
+
+
+template <class VectorType>
+inline
+typename BlockVectorBase<VectorType>::value_type
+BlockVectorBase<VectorType>::operator[] (const unsigned int i) const
+{
+ return operator()(i);
+}
+
+
+
+template <class VectorType>
+inline
+typename BlockVectorBase<VectorType>::reference
+BlockVectorBase<VectorType>::operator[] (const unsigned int i)
+{
+ return operator()(i);
+}
+
#endif // DOXYGEN
DEAL_II_NAMESPACE_CLOSE
//@{
/**
- * Read access to the data in the position
- * corresponding to @p global_index. The index
- * must be either in the local range of the
- * vector or be specified as a ghost index at
- * construction.
+ * Read access to the data in the
+ * position corresponding to @p
+ * global_index. The index must be
+ * either in the local range of the
+ * vector or be specified as a ghost
+ * index at construction.
+ */
+ Number operator () (const types::global_dof_index global_index) const;
+
+ /**
+ * Read and write access to the data
+ * in the position corresponding to
+ * @p global_index. The index must be
+ * either in the local range of the
+ * vector or be specified as a ghost
+ * index at construction.
*/
- Number operator() (const types::global_dof_index global_index) const;
+ Number& operator () (const types::global_dof_index global_index);
/**
- * Read and write access to the data in the
+ * Read access to the data in the
* position corresponding to @p
- * global_index. The index must be either in
- * the local range of the vector or be
- * specified as a ghost index at construction.
+ * global_index. The index must be
+ * either in the local range of the
+ * vector or be specified as a ghost
+ * index at construction.
+ *
+ * This function does the same thing
+ * as operator().
*/
- Number& operator() (const types::global_dof_index global_index);
+ Number operator [] (const types::global_dof_index global_index) const;
+
+ /**
+ * Read and write access to the data
+ * in the position corresponding to
+ * @p global_index. The index must be
+ * either in the local range of the
+ * vector or be specified as a ghost
+ * index at construction.
+ *
+ * This function does the same thing
+ * as operator().
+ */
+ Number& operator [] (const types::global_dof_index global_index);
/**
* Read access to the data field specified by
+ template <typename Number>
+ inline
+ Number
+ Vector<Number>::operator[] (const types::global_dof_index global_index) const
+ {
+ return operator()(global_index);
+ }
+
+
+
+ template <typename Number>
+ inline
+ Number&
+ Vector<Number>::operator[] (const types::global_dof_index global_index)
+ {
+ return operator()(global_index);
+ }
+
+
+
template <typename Number>
inline
Number
template <typename Number>
inline
bool
- Vector<Number>::partitioners_are_compatible
+ Vector<Number>::partitioners_are_compatible
(const Utilities::MPI::Partitioner &part) const
{
return partitioner->is_compatible (part);
//---------------------------------------------------------------------------
// $Id$
//
-// Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 by the deal.II authors
+// Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
* PETSc object in the destructor.
*/
explicit VectorBase (const Vec & v);
-
+
/**
* Destructor
*/
* elements.
*/
bool has_ghost_elements() const;
-
+
/**
* Provide access to a given element,
* both read and write.
PetscScalar
operator () (const unsigned int index) const;
+ /**
+ * Provide access to a given
+ * element, both read and write.
+ *
+ * Exactly the same as operator().
+ */
+ reference
+ operator [] (const unsigned int index);
+
+ /**
+ * Provide read-only access to an
+ * element. This is equivalent to
+ * the <code>el()</code> command.
+ *
+ * Exactly the same as operator().
+ */
+ PETScScalar
+ operator [] (const unsigned int index) const;
+
/**
* A collective set operation: instead
* of setting individual elements of a
* the destructor.
*/
bool attained_ownership;
-
+
/**
* Collective set or add
* operation: This function is
{
return ghosted;
}
-
+
inline
}
+
+ inline
+ internal::VectorReference
+ VectorBase::operator [] (const unsigned int index)
+ {
+ return operator()(index);
+ }
+
+
+
+ inline
+ PetscScalar
+ VectorBase::operator [] (const unsigned int index) const
+ {
+ return operator()(index);
+ }
+
+
#endif // DOXYGEN
}
//---------------------------------------------------------------------------
// $Id$
//
-// Copyright (C) 2008, 2009, 2010, 2011 by the deal.II authors
+// Copyright (C) 2008, 2009, 2010, 2011, 2012 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
TrilinosScalar
operator () (const unsigned int index) const;
+ /**
+ * Provide access to a given
+ * element, both read and write.
+ *
+ * Exactly the same as operator().
+ */
+ reference
+ operator [] (const unsigned int index);
+
+ /**
+ * Provide read-only access to an
+ * element. This is equivalent to
+ * the <code>el()</code> command.
+ *
+ * Exactly the same as operator().
+ */
+ TrilinosScalar
+ operator [] (const unsigned int index) const;
+
/**
* Return the value of the vector
* entry <i>i</i>. Note that this
+ inline
+ internal::VectorReference
+ VectorBase::operator [] (const unsigned int index)
+ {
+ return operator() (index);
+ }
+
+
+ inline
+ TrilinosScalar
+ VectorBase::operator [] (const unsigned int index) const
+ {
+ return operator() (index);
+ }
+
+
+
inline
void
VectorBase::reinit (const VectorBase &v,
//---------------------------------------------------------------------------
// $Id$
//
-// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 by the deal.II authors
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
* as a writeable reference.
*/
Number& operator() (const unsigned int i);
+
+ /**
+ * Access the value of the @p ith
+ * component.
+ *
+ * Exactly the same as operator().
+ */
+ Number operator[] (const unsigned int i) const;
+
+ /**
+ * Access the @p ith component
+ * as a writeable reference.
+ *
+ * Exactly the same as operator().
+ */
+ Number& operator[] (const unsigned int i);
//@}
+template <typename Number>
+inline
+Number Vector<Number>::operator[] (const unsigned int i) const
+{
+ return operator()(i);
+}
+
+
+
+template <typename Number>
+inline
+Number& Vector<Number>::operator[] (const unsigned int i)
+{
+ return operator()(i);
+}
+
+
+
template <typename Number>
inline
Vector<Number> & Vector<Number>::operator *= (const Number factor)