DUNE PDELab (git)

densevectorview.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_COMMON_DENSEVECTORVIEW_HH
8#define DUNE_FUNCTIONS_COMMON_DENSEVECTORVIEW_HH
9
10#include <type_traits>
11
13
14
15namespace Dune::Functions::Impl {
16
20 template<class R>
21 class DenseVectorView
22 : public DenseVector<DenseVectorView<R>>
23 {
24 R& data_;
25
26 using mutable_reference = typename std::decay_t<R>::reference;
27
28 public:
29
31 using size_type = typename std::decay_t<R>::size_type;
32
34 using value_type = typename std::decay_t<R>::value_type;
35
37 using const_reference = typename std::decay_t<R>::const_reference;
38
40 using reference = std::conditional_t<std::is_const_v<R>,
41 const_reference,
42 mutable_reference>;
43
45 DenseVectorView (R& data)
46 : data_(data)
47 {}
48
50 DenseVectorView (const DenseVectorView &other) = delete;
51
53 DenseVectorView (DenseVectorView &&other) :
54 data_( other.data_ )
55 {}
56
58 DenseVectorView& operator= (const DenseVectorView& other)
59 {
60 data_ = other.data_;
61 return *this;
62 }
63
65 template<class RR>
66 DenseVectorView& operator= (const DenseVectorView<RR>& other)
67 {
68 data_ = other.data_;
69 return *this;
70 }
71
73 size_type size () const
74 {
75 return data_.size();
76 }
77
79 reference operator[] (size_type i)
80 {
81 return data_[i];
82 }
83
85 const_reference operator[] (size_type i) const
86 {
87 return data_[i];
88 }
89
90 }; // class DenseVectorView
91
92}
93
94namespace Dune {
95
96 template< class R>
97 struct DenseMatVecTraits< Dune::Functions::Impl::DenseVectorView<R> >
98 {
99 using derived_type = Dune::Functions::Impl::DenseVectorView<R>;
100 using value_type = typename R::value_type;
101 using size_type = typename R::size_type;
102 };
103
104 template< class R >
105 struct FieldTraits< Dune::Functions::Impl::DenseVectorView<R> >
106 : public FieldTraits<std::remove_const_t<typename Dune::Functions::Impl::DenseVectorView<R>::value_type>>
107 {};
108
109}
110
111
112#endif // DUNE_FUNCTIONS_COMMON_DENSEVECTORVIEW_HH
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:250
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:259
Implements the dense vector interface, with an exchangeable storage class.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jan 9, 23:30, 2025)