dune-assembler 2.11
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 using index_type = typename Base::index_type;
23 using value_type = typename Base::value_type;
24 using extents_type = typename Base::extents_type;
25
26public:
27 using Base::Base;
28
29 explicit constexpr FlatArray (const value_type& value)
30 : Base(extents_type{}, value)
31 {}
32
33 constexpr FlatArray& operator= (const value_type& value)
34 {
35 for (index_type i = 0; i < size(); ++i)
36 (*this)[i] = value;
37 return *this;
38 }
39
40 static constexpr index_type size () noexcept { return Base::static_extent(0); }
41};
42
43
44template <class T, std::size_t R, std::size_t C>
45class FlatArray<T,R,C>
46 : public Std::mdarray<T, Std::extents<std::size_t,R,C>, Std::layout_right, std::array<T,R*C>>
47{
49 using index_type = typename Base::index_type;
50 using value_type = typename Base::value_type;
51 using extents_type = typename Base::extents_type;
52
53 template <class Self>
54 struct BracketProxy
55 {
56 constexpr auto& operator[] (index_type j) const { return (*self_)(i_,j); }
57 Self* self_;
58 index_type i_;
59 };
60
61public:
62 using Base::Base;
63
64 explicit constexpr FlatArray (const value_type& value)
65 : Base(extents_type{}, value)
66 {}
67
68 constexpr FlatArray& operator= (const value_type& value)
69 {
70 for (index_type i = 0; i < rows(); ++i)
71 for (index_type j = 0; j < cols(); ++j)
72 (*this)[i][j] = value;
73 return *this;
74 }
75
76 constexpr BracketProxy<const FlatArray> operator[] (index_type i) const { return {this,i}; }
77 constexpr BracketProxy<FlatArray> operator[] (index_type i) { return {this,i}; }
78
79 static constexpr index_type rows () noexcept { return Base::static_extent(0); }
80 static constexpr index_type cols () noexcept { return Base::static_extent(1); }
81};
82
83} // end namespace Dune::Assembler
84
85#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
static constexpr index_type size() noexcept
Definition flatarray.hh:40
constexpr FlatArray(const value_type &value)
Definition flatarray.hh:29
constexpr FlatArray(const value_type &value)
Definition flatarray.hh:64
static constexpr index_type rows() noexcept
Definition flatarray.hh:79
static constexpr index_type cols() noexcept
Definition flatarray.hh:80