From: Daniel Arndt Date: Fri, 2 Nov 2018 19:33:25 +0000 (+0100) Subject: Let ArrayView have a MemorySpace template parameter X-Git-Tag: v9.1.0-rc1~571^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=968857aed4d127544726184494146d91dd0febaf;p=dealii.git Let ArrayView have a MemorySpace template parameter --- diff --git a/include/deal.II/base/array_view.h b/include/deal.II/base/array_view.h index 91e5aa7ac3..92aa30e8e9 100644 --- a/include/deal.II/base/array_view.h +++ b/include/deal.II/base/array_view.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -72,7 +73,7 @@ DEAL_II_NAMESPACE_OPEN * @ingroup data * @author Wolfgang Bangerth, 2015, David Wells, 2017 */ -template +template class ArrayView { public: @@ -122,7 +123,8 @@ public: * non-@p const view to a @p const view, akin to converting a non-@p const * pointer to a @p const pointer. */ - ArrayView(const ArrayView::type> &view); + ArrayView(const ArrayView::type, + MemorySpaceType> &view); /** * A constructor that automatically creates a view from a std::vector object. @@ -163,7 +165,8 @@ public: * This version always compares with the const value_type. */ bool - operator==(const ArrayView &other_view) const; + operator==( + const ArrayView &other_view) const; /** * Compare two ArrayView objects of the same type. Two objects are considered @@ -171,8 +174,8 @@ public: * This version always compares with the non-const value_type. */ bool - operator==(const ArrayView::type> - &other_view) const; + operator==(const ArrayView::type, + MemorySpaceType> &other_view) const; /** * Compare two ArrayView objects of the same type. Two objects are considered @@ -180,7 +183,8 @@ public: * This version always compares with the const value_type. */ bool - operator!=(const ArrayView &other_view) const; + operator!=( + const ArrayView &other_view) const; /** * Compare two ArrayView objects of the same type. Two objects are considered @@ -188,8 +192,8 @@ public: * This version always compares with the non-const value_type. */ bool - operator!=(const ArrayView::type> - &other_view) const; + operator!=(const ArrayView::type, + MemorySpaceType> &other_view) const; /** * Return the size (in elements) of the view of memory this object @@ -252,7 +256,7 @@ private: */ const std::size_t n_elements; - friend class ArrayView; + friend class ArrayView; }; @@ -261,26 +265,28 @@ private: -template -inline ArrayView::ArrayView(value_type * starting_element, - const std::size_t n_elements) +template +inline ArrayView::ArrayView( + value_type * starting_element, + const std::size_t n_elements) : starting_element(starting_element) , n_elements(n_elements) {} -template -inline ArrayView::ArrayView( - const ArrayView::type> &view) +template +inline ArrayView::ArrayView( + const ArrayView::type, MemorySpaceType> + &view) : starting_element(view.starting_element) , n_elements(view.n_elements) {} -template -inline ArrayView::ArrayView( +template +inline ArrayView::ArrayView( const std::vector::type> &vector) : // use delegating constructor ArrayView(vector.data(), vector.size()) @@ -303,8 +309,8 @@ inline ArrayView::ArrayView( -template -inline ArrayView::ArrayView( +template +inline ArrayView::ArrayView( std::vector::type> &vector) : // use delegating constructor ArrayView(vector.data(), vector.size()) @@ -312,10 +318,10 @@ inline ArrayView::ArrayView( -template +template inline bool -ArrayView:: -operator==(const ArrayView &other_view) const +ArrayView:: +operator==(const ArrayView &other_view) const { return (other_view.data() == starting_element) && (other_view.size() == n_elements); @@ -323,10 +329,11 @@ operator==(const ArrayView &other_view) const -template +template inline bool -ArrayView::operator==( - const ArrayView::type> &other_view) const +ArrayView:: +operator==(const ArrayView::type, + MemorySpaceType> &other_view) const { return (other_view.data() == starting_element) && (other_view.size() == n_elements); @@ -334,19 +341,19 @@ ArrayView::operator==( -template +template inline bool -ArrayView:: -operator!=(const ArrayView &other_view) const +ArrayView:: +operator!=(const ArrayView &other_view) const { return !(*this == other_view); } -template -inline typename ArrayView::value_type * -ArrayView::data() const noexcept +template +inline typename ArrayView::value_type * +ArrayView::data() const noexcept { if (n_elements == 0) return nullptr; @@ -356,62 +363,63 @@ ArrayView::data() const noexcept -template +template inline bool -ArrayView::operator!=( - const ArrayView::type> &other_view) const +ArrayView:: +operator!=(const ArrayView::type, + MemorySpaceType> &other_view) const { return !(*this == other_view); } -template +template inline std::size_t -ArrayView::size() const +ArrayView::size() const { return n_elements; } -template -inline typename ArrayView::iterator -ArrayView::begin() const +template +inline typename ArrayView::iterator +ArrayView::begin() const { return starting_element; } -template -inline typename ArrayView::iterator -ArrayView::end() const +template +inline typename ArrayView::iterator +ArrayView::end() const { return starting_element + n_elements; } -template -inline typename ArrayView::const_iterator -ArrayView::cbegin() const +template +inline typename ArrayView::const_iterator +ArrayView::cbegin() const { return starting_element; } -template -inline typename ArrayView::const_iterator -ArrayView::cend() const +template +inline typename ArrayView::const_iterator +ArrayView::cend() const { return starting_element + n_elements; } -template -inline typename ArrayView::value_type &ArrayView:: - operator[](const std::size_t i) const +template +inline typename ArrayView::value_type & + ArrayView::operator[](const std::size_t i) const { Assert(i < n_elements, ExcIndexRange(i, 0, n_elements)); @@ -481,9 +489,10 @@ namespace internal * * @relatesalso ArrayView */ -template +template ArrayView::reference>::type> + typename std::iterator_traits::reference>::type, + MemorySpaceType> make_array_view(const Iterator begin, const Iterator end) { static_assert( @@ -497,8 +506,8 @@ make_array_view(const Iterator begin, const Iterator end) ExcMessage("The provided range isn't contiguous in memory!")); // the reference type, not the value type, knows the constness of the iterator return ArrayView::reference>::type>( - std::addressof(*begin), end - begin); + typename std::iterator_traits::reference>::type, + MemorySpaceType>(std::addressof(*begin), end - begin); } @@ -512,14 +521,14 @@ make_array_view(const Iterator begin, const Iterator end) * * @relatesalso ArrayView */ -template -ArrayView +template +ArrayView make_array_view(ElementType *const begin, ElementType *const end) { Assert(begin <= end, ExcMessage( "The beginning of the array view should be before the end.")); - return ArrayView(begin, end - begin); + return ArrayView(begin, end - begin); } @@ -534,9 +543,9 @@ make_array_view(ElementType *const begin, ElementType *const end) * * @relatesalso ArrayView */ -template -inline ArrayView -make_array_view(const ArrayView &array_view) +template +inline ArrayView +make_array_view(const ArrayView &array_view) { return make_array_view(array_view.cbegin(), array_view.cend()); } @@ -553,9 +562,9 @@ make_array_view(const ArrayView &array_view) * * @relatesalso ArrayView */ -template -inline ArrayView -make_array_view(ArrayView &array_view) +template +inline ArrayView +make_array_view(ArrayView &array_view) { return make_array_view(array_view.begin(), array_view.end()); } diff --git a/include/deal.II/fe/mapping.h b/include/deal.II/fe/mapping.h index b5ca1f949f..21bec9ebc2 100644 --- a/include/deal.II/fe/mapping.h +++ b/include/deal.II/fe/mapping.h @@ -31,7 +31,7 @@ DEAL_II_NAMESPACE_OPEN -template +template class ArrayView; template class Quadrature;