dune-assembler 2.12
Loading...
Searching...
No Matches
flatarray.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_ASSEMBLER_BACKEND_FLATARRAY_HH
5#define DUNE_ASSEMBLER_BACKEND_FLATARRAY_HH
6
7#include <array>
8
11
12namespace Dune::Assembler {
13
14template <class T, std::size_t...>
16
17template <class T, std::size_t N>
20{
22
23public:
24 using index_type = typename Base::index_type;
25 using value_type = typename Base::value_type;
27
28 using Base::Base;
29
30 explicit constexpr FlatArray (const value_type& value)
31 : Base(extents_type{}, value)
32 {}
33
34 constexpr FlatArray& operator= (const value_type& value)
35 {
36 for (index_type i = 0; i < size(); ++i)
37 (*this)[i] = value;
38 return *this;
39 }
40
41 static constexpr index_type size () noexcept { return Base::static_extent(0); }
42};
43
44
45template <class T, std::size_t R, std::size_t C>
46class FlatArray<T,R,C>
47 : public Std::mdarray<T, Std::extents<std::size_t,R,C>, Std::layout_right, std::array<T,R*C>>
48{
50
51public:
52
53 using index_type = typename Base::index_type;
54 using value_type = typename Base::value_type;
56
57private:
58 template <class Self>
59 struct BracketProxy
60 {
61 constexpr auto& operator[] (index_type j) const { return (*self_)(i_,j); }
62 Self* self_;
63 index_type i_;
64 };
65
66public:
67 using Base::Base;
68
69 explicit constexpr FlatArray (const value_type& value)
70 : Base(extents_type{}, value)
71 {}
72
73 constexpr FlatArray& operator= (const value_type& value)
74 {
75 for (index_type i = 0; i < rows(); ++i)
76 for (index_type j = 0; j < cols(); ++j)
77 (*this)[i][j] = value;
78 return *this;
79 }
80
81 constexpr BracketProxy<const FlatArray> operator[] (index_type i) const { return {this,i}; }
82 constexpr BracketProxy<FlatArray> operator[] (index_type i) { return {this,i}; }
83
84 static constexpr index_type rows () noexcept { return Base::static_extent(0); }
85 static constexpr index_type cols () noexcept { return Base::static_extent(1); }
86};
87
88} // end namespace Dune::Assembler
89
90#endif // DUNE_ASSEMBLER_BACKEND_FLATARRAY_HH
Definition localboundaryintersectionmatrixassembler.hh:9
reference operator[](size_type i)
int size() const
SLList< T, A > & operator=(const SLList< T, A > &other)
Definition flatarray.hh:15
typename Base::value_type value_type
Definition flatarray.hh:25
typename Base::extents_type extents_type
Definition flatarray.hh:26
typename Base::index_type index_type
Definition flatarray.hh:24
static constexpr index_type size() noexcept
Definition flatarray.hh:41
constexpr FlatArray(const value_type &value)
Definition flatarray.hh:30
typename Base::extents_type extents_type
Definition flatarray.hh:55
constexpr FlatArray(const value_type &value)
Definition flatarray.hh:69
static constexpr index_type rows() noexcept
Definition flatarray.hh:84
typename Base::value_type value_type
Definition flatarray.hh:54
static constexpr index_type cols() noexcept
Definition flatarray.hh:85
typename Base::index_type index_type
Definition flatarray.hh:53