16 #ifndef dealii_array_view_h 17 #define dealii_array_view_h 19 #include <deal.II/base/config.h> 20 #include <deal.II/base/exceptions.h> 21 #include <deal.II/base/table.h> 22 #include <deal.II/lac/lapack_full_matrix.h> 23 #include <deal.II/base/tensor.h> 26 #include <type_traits> 29 DEAL_II_NAMESPACE_OPEN
72 template <
typename ElementType>
139 ArrayView (
const std::vector<
typename std::remove_cv<value_type>::type> &vector);
155 ArrayView (std::vector<
typename std::remove_cv<value_type>::type> &vector);
191 std::size_t
size()
const;
242 friend class
ArrayView<const ElementType>;
251 template <typename ElementType>
262 template <
typename ElementType>
273 template <
typename ElementType>
276 ArrayView (
const std::vector<
typename std::remove_cv<value_type>::type> &vector)
290 static_assert (std::is_const<value_type>::value ==
true,
291 "This constructor may only be called if the ArrayView " 292 "object has a const value_type. In other words, you can " 293 "only create an ArrayView to const values from a const " 299 template <
typename ElementType>
302 ArrayView (std::vector<
typename std::remove_cv<value_type>::type> &vector)
310 template <
typename ElementType>
315 return (other_view.
data() == starting_element)
316 && (other_view.
size() == n_elements);
321 template <
typename ElementType>
327 return (other_view.data() == starting_element)
328 && (other_view.size() == n_elements);
333 template <
typename ElementType>
338 return !(*
this == other_view);
343 template <
typename ElementType>
351 return starting_element;
356 template <
typename ElementType>
362 return !(*
this == other_view);
367 template <
typename ElementType>
375 template <
typename ElementType>
380 return starting_element;
385 template <
typename ElementType>
390 return starting_element + n_elements;
395 template <
typename ElementType>
400 return starting_element;
405 template <
typename ElementType>
410 return starting_element + n_elements;
415 template <
typename ElementType>
422 return *(starting_element + i);
430 namespace ArrayViewHelper
437 template <
class Iterator>
438 bool is_contiguous(
const Iterator &first,
const Iterator &last)
440 const auto n = std::distance(first, last);
441 for (
typename std::decay<decltype(n)>::type i = 0; i < n; ++i)
442 if (std::addressof(*(std::next(first, i))) != std::next(std::addressof(*first), i))
460 bool is_contiguous(T *,
488 template <
typename Iterator>
492 static_assert(std::is_same<
typename std::iterator_traits<Iterator>::iterator_category,
493 typename std::random_access_iterator_tag>::value,
494 "The provided iterator should be a random access iterator.");
496 ExcMessage(
"The beginning of the array view should be before the end."));
497 Assert(internal::ArrayViewHelper::is_contiguous(begin, end),
498 ExcMessage(
"The provided range isn't contiguous in memory!"));
500 return ArrayView<
typename std::remove_reference
501 <
typename std::iterator_traits<Iterator>::reference>::type>
502 (std::addressof(*begin), end - begin);
516 template <
typename ElementType>
521 ExcMessage(
"The beginning of the array view should be before the end."));
537 template <
typename Number>
557 template <
typename Number>
583 template <
int rank,
int dim,
typename Number>
609 template <
int rank,
int dim,
typename Number>
635 template <
int rank,
int dim,
typename Number>
662 template <
int rank,
int dim,
typename Number>
685 template <
typename ElementType,
int N>
709 template <
typename ElementType>
733 template <
typename ElementType>
757 template <
typename ElementType>
781 template <
typename ElementType>
810 template <
typename ElementType>
814 const std::size_t starting_index,
815 const std::size_t size_of_view)
817 Assert (starting_index + size_of_view <= vector.size(),
818 ExcMessage (
"The starting index and size of the view you want to " 819 "create would lead to a view that extends beyond the end " 820 "of the given vector."));
845 template <
typename ElementType>
849 const std::size_t starting_index,
850 const std::size_t size_of_view)
852 Assert (starting_index + size_of_view <= vector.size(),
853 ExcMessage (
"The starting index and size of the view you want to " 854 "create would lead to a view that extends beyond the end " 855 "of the given vector."));
877 template <
typename ElementType>
905 template <
typename ElementType>
931 template <
typename ElementType>
957 template <
typename ElementType>
983 template <
typename ElementType>
1009 template <
typename ElementType>
1040 template <
typename ElementType>
1046 const std::size_t size_of_view)
1050 Assert (starting_column + size_of_view <= table.
size()[1],
1051 ExcMessage (
"The starting index and size of the view you want to " 1052 "create would lead to a view that extends beyond the end " 1053 "of a column of the given table."));
1078 template <
typename ElementType>
1084 const std::size_t size_of_view)
1088 Assert (starting_column + size_of_view <= table.
size()[1],
1089 ExcMessage (
"The starting index and size of the view you want to " 1090 "create would lead to a view that extends beyond the end " 1091 "of a column of the given table."));
1097 DEAL_II_NAMESPACE_CLOSE
ArrayView< ElementType > make_array_view(LAPACKFullMatrix< ElementType > &matrix)
ArrayView< const ElementType > make_array_view(const LAPACKFullMatrix< ElementType > &matrix)
ArrayView< const Number > make_array_view(const ArrayView< Number > &array_view)
ArrayView< ElementType > make_array_view(ElementType(&array)[N])
ArrayView< const Number > make_array_view(const Tensor< rank, dim, Number > &tensor)
ArrayView< ElementType > make_array_view(std::vector< ElementType > &vector, const std::size_t starting_index, const std::size_t size_of_view)
const std::size_t n_elements
#define AssertIndexRange(index, range)
bool operator==(const ArrayView< const value_type > &other_view) const
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
ArrayView< const ElementType > make_array_view(const Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row, const typename Table< 2, ElementType >::size_type starting_column, const std::size_t size_of_view)
const_iterator cend() const
ArrayView< Number > make_array_view(SymmetricTensor< rank, dim, Number > &tensor)
ArrayView< ElementType > make_array_view(Vector< ElementType > &vector)
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type > make_array_view(const Iterator begin, const Iterator end)
value_type & operator[](const std::size_t i) const
static ::ExceptionBase & ExcMessage(std::string arg1)
ArrayView< ElementType > make_array_view(ElementType *const begin, ElementType *const end)
#define Assert(cond, exc)
ArrayView< ElementType > make_array_view(Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row)
ArrayView< const ElementType > make_array_view(const std::vector< ElementType > &vector, const std::size_t starting_index, const std::size_t size_of_view)
ArrayView< const Number > make_array_view(const SymmetricTensor< rank, dim, Number > &tensor)
size_type size(const unsigned int i) const
ArrayView< const ElementType > make_array_view(const Vector< ElementType > &vector)
ArrayView< ElementType > make_array_view(std::vector< ElementType > &vector)
const_iterator cbegin() const
ArrayView(value_type *starting_element, const std::size_t n_elements)
ArrayView< const ElementType > make_array_view(const Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row)
value_type * data() const noexcept
ArrayView< Number > make_array_view(ArrayView< Number > &array_view)
const ElementType * const_iterator
ArrayView< ElementType > make_array_view(Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row, const typename Table< 2, ElementType >::size_type starting_column, const std::size_t size_of_view)
bool operator!=(const ArrayView< const value_type > &other_view) const
AlignedVector< T >::size_type size_type
ArrayView< Number > make_array_view(Tensor< rank, dim, Number > &tensor)
ArrayView< const ElementType > make_array_view(const std::vector< ElementType > &vector)
ArrayView< const ElementType > make_array_view(const Table< 2, ElementType > &table)
value_type *const starting_element
ArrayView< ElementType > make_array_view(Table< 2, ElementType > &table)