Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
vector_slice.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_vector_slice_h
17 #define dealii_vector_slice_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/array_view.h>
22 #include <deal.II/base/exceptions.h>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
50 template <typename VectorType>
51 class DEAL_II_DEPRECATED VectorSlice
52  : public ArrayView<
53  typename std::conditional<std::is_const<VectorType>::value,
54  const typename VectorType::value_type,
55  typename VectorType::value_type>::type>
56 {
57 public:
64  VectorSlice(VectorType &v);
69  VectorSlice(VectorType &v, unsigned int start, unsigned int length);
70 
71 protected:
75  using ArrayViewType =
77  const typename VectorType::value_type,
78  typename VectorType::value_type>::type>;
79 };
80 
81 
89 template <typename VectorType>
91 make_slice(VectorType &v)
92 {
94  return r;
95 }
96 
97 
98 
106 template <typename VectorType>
108 make_slice(VectorType &v, const unsigned int start, const unsigned int length)
109 {
110  const VectorSlice<const VectorType> r(v, start, length);
111  return r;
112 }
113 
114 
115 
116 //---------------------------------------------------------------------------
117 
118 template <typename VectorType>
120  : ArrayViewType(make_array_view(std::begin(v), std::end(v)))
121 {}
122 
123 
124 
125 template <typename VectorType>
127  unsigned int start,
128  unsigned int length)
129  : ArrayViewType(
130  make_array_view(std::begin(v) + start, std::begin(v) + start + length))
131 {
132  Assert((start + length <= v.size()),
133  ExcIndexRange(length, 0, v.size() - start + 1));
134 }
135 
136 DEAL_II_NAMESPACE_CLOSE
137 
138 #endif
STL namespace.
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
const VectorSlice< const VectorType > make_slice(VectorType &v)
Definition: vector_slice.h:91
#define Assert(cond, exc)
Definition: exceptions.h:1407
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
Definition: array_view.h:594
VectorSlice(VectorType &v)
Definition: vector_slice.h:119
const VectorSlice< const VectorType > make_slice(VectorType &v, const unsigned int start, const unsigned int length)
Definition: vector_slice.h:108