]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce operator== and operator!= for ArrayView
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 3 Oct 2017 22:53:11 +0000 (00:53 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 4 Oct 2017 21:36:17 +0000 (23:36 +0200)
include/deal.II/base/array_view.h

index 0cad1ad043250087dba306aefae49780ccd256c2..7086d56d3398b7e0b0a6638cfd68fb416562acc8 100644 (file)
@@ -157,6 +157,35 @@ public:
    */
   ArrayView (std::vector<typename std::remove_cv<value_type>::type> &vector);
 
+  /**
+   * Compare two ArrayView objects of the same type. Two objects are considered
+   * equal if they have the same size and the same starting pointer.
+   * This version always compares with the const value_type.
+   */
+  bool operator == (const ArrayView<const value_type> &other_view) const;
+
+  /**
+   * Compare two ArrayView objects of the same type. Two objects are considered
+   * equal if they have the same size and the same starting pointer.
+   * This version always compares with the non-const value_type.
+   */
+  bool operator ==
+  (const ArrayView<typename std::remove_cv<value_type>::type> &other_view) const;
+
+  /**
+   * Compare two ArrayView objects of the same type. Two objects are considered
+   * equal if they have the same size and the same starting pointer.
+   * This version always compares with the const value_type.
+   */
+  bool operator != (const ArrayView<const value_type> &other_view) const;
+
+  /**
+   * Compare two ArrayView objects of the same type. Two objects are considered
+   * equal if they have the same size and the same starting pointer.
+   * This version always comapres with the non-const value_type.
+   */
+  bool operator !=
+  (const ArrayView<typename std::remove_cv<value_type>::type> &other_view) const;
 
   /**
    * Return the size (in elements) of the view of memory this object
@@ -285,6 +314,49 @@ ArrayView (std::vector<typename std::remove_cv<value_type>::type> &vector)
 
 
 
+template <typename ElementType>
+inline
+bool
+ArrayView<ElementType>::operator == (const ArrayView<const value_type> &other_view) const
+{
+  return (other_view.begin() == starting_element)
+         && (other_view.size() == n_elements);
+}
+
+
+
+template <typename ElementType>
+inline
+bool
+ArrayView<ElementType>::operator ==
+(const ArrayView<typename std::remove_cv<value_type>::type> &other_view) const
+{
+  return (other_view.begin() == starting_element)
+         && (other_view.size() == n_elements);
+}
+
+
+
+template <typename ElementType>
+inline
+bool
+ArrayView<ElementType>::operator != (const ArrayView<const value_type> &other_view) const
+{
+  return !(*this == other_view);
+}
+
+
+
+template <typename ElementType>
+inline
+bool
+ArrayView<ElementType>::operator !=
+(const ArrayView<typename std::remove_cv<value_type>::type> &other_view) const
+{
+  return !(*this == other_view);
+}
+
+
 
 template <typename ElementType>
 inline

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.