Dune Core Modules (2.4.1)

array.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_ARRAY_HH
5#define DUNE_ARRAY_HH
6
11#include <array>
12#include <iostream>
13
14namespace Dune
15{
21 // pull in default implementation
22 using std::array;
23
25 template < class T, size_t N >
26 inline std::ostream& operator<< (std::ostream& s, const array<T,N>& e)
27 {
28 if (N == 0)
29 {
30 s << "[]";
31 return s;
32 }
33
34 s << "[";
35 for (size_t i=0; i<N-1; i++) s << e[i] << ",";
36 s << e[N-1] << "]";
37 return s;
38 }
39
40#ifndef DOXYGEN
41 template<class T>
42 array<T, 1> make_array(const T &t0) {
43 array<T, 1> result = { {t0} };
44 return result;
45 }
46
47 template<class T>
48 array<T, 2> make_array(const T &t0, const T &t1) {
49 array<T, 2> result = { {t0, t1} };
50 return result;
51 }
52
53 template<class T>
54 array<T, 3> make_array(const T &t0, const T &t1, const T &t2) {
55 array<T, 3> result = { {t0, t1, t2} };
56 return result;
57 }
58
59 template<class T>
60 array<T, 4> make_array(const T &t0, const T &t1, const T &t2, const T &t3) {
61 array<T, 4> result = { {t0, t1, t2, t3} };
62 return result;
63 }
64
65 template<class T>
66 array<T, 5> make_array(const T &t0, const T &t1, const T &t2, const T &t3,
67 const T &t4)
68 {
69 array<T, 5> result = { {t0, t1, t2, t3, t4} };
70 return result;
71 }
72
73 template<class T>
74 array<T, 6> make_array(const T &t0, const T &t1, const T &t2, const T &t3,
75 const T &t4, const T &t5)
76 {
77 array<T, 6> result = { {t0, t1, t2, t3, t4, t5} };
78 return result;
79 }
80
81 template<class T>
82 array<T, 7> make_array(const T &t0, const T &t1, const T &t2, const T &t3,
83 const T &t4, const T &t5, const T &t6)
84 {
85 array<T, 7> result = { {t0, t1, t2, t3, t4, t5, t6} };
86 return result;
87 }
88
89 template<class T>
90 array<T, 8> make_array(const T &t0, const T &t1, const T &t2, const T &t3,
91 const T &t4, const T &t5, const T &t6, const T &t7)
92 {
93 array<T, 8> result = { {t0, t1, t2, t3, t4, t5, t6, t7} };
94 return result;
95 }
96
97 template<class T>
98 array<T, 9> make_array(const T &t0, const T &t1, const T &t2, const T &t3,
99 const T &t4, const T &t5, const T &t6, const T &t7,
100 const T &t8)
101 {
102 array<T, 9> result = { {t0, t1, t2, t3, t4, t5, t6, t7, t8} };
103 return result;
104 }
105#endif // !DOXYGEN
106
108
114 template<class T>
115 array<T, 10> make_array(const T &t0, const T &t1, const T &t2, const T &t3,
116 const T &t4, const T &t5, const T &t6, const T &t7,
117 const T &t8, const T &t9)
118 {
119 array<T, 10> result = { {t0, t1, t2, t3, t4, t5, t6, t7, t8, t9} };
120 return result;
121 }
122
124
127 template<typename T, std::size_t n>
128 array<T,n> fill_array(const T& t)
129 {
130 array<T,n> r;
131 r.fill(t);
132 return std::move(r);
133 }
134
137} // end namespace Dune
138
139#endif
array< T, 10 > make_array(const T &t0, const T &t1, const T &t2, const T &t3, const T &t4, const T &t5, const T &t6, const T &t7, const T &t8, const T &t9)
create an initialize an array
Definition: array.hh:115
array< T, n > fill_array(const T &t)
Create an array and fill it with copies of the provided value.
Definition: array.hh:128
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:26
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)