dune-common 2.8.0
Loading...
Searching...
No Matches
dynvector.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#ifndef DUNE_DYNVECTOR_HH
4#define DUNE_DYNVECTOR_HH
5
6#include <cmath>
7#include <cstddef>
8#include <cstdlib>
9#include <complex>
10#include <cstring>
11#include <initializer_list>
12#include <limits>
13#include <utility>
14
15#include "boundschecking.hh"
16#include "exceptions.hh"
17#include "genericiterator.hh"
18
19#include <vector>
20#include "densevector.hh"
21
22namespace Dune {
23
32 template< class K, class Allocator > class DynamicVector;
33 template< class K, class Allocator >
34 struct DenseMatVecTraits< DynamicVector< K, Allocator > >
35 {
38 typedef K value_type;
39 typedef typename container_type::size_type size_type;
40 };
41
42 template< class K, class Allocator >
43 struct FieldTraits< DynamicVector< K, Allocator > >
44 {
47 };
48
55 template< class K, class Allocator = std::allocator< K > >
56 class DynamicVector : public DenseVector< DynamicVector< K, Allocator > >
57 {
59
61 public:
62 typedef typename Base::size_type size_type;
63 typedef typename Base::value_type value_type;
64
66
67 typedef Allocator allocator_type;
68
71 _data( a )
72 {}
73
75 _data( n, value_type(), a )
76 {}
77
80 _data( n, c, a )
81 {}
82
85 _data(l)
86 {}
87
90 Base(), _data(x._data)
91 {}
92
95 _data(std::move(x._data))
96 {}
97
98 template< class T >
100 _data(x.begin(), x.end(), x.get_allocator())
101 {}
102
104 template< class X >
106 _data(a)
107 {
108 const size_type n = x.size();
109 _data.reserve(n);
110 for( size_type i =0; i<n ;++i)
111 _data.push_back( x[ i ] );
112 }
113
114 using Base::operator=;
115
118 {
119 _data = other._data;
120 return *this;
121 }
122
125 {
126 _data = std::move(other._data);
127 return *this;
128 }
129
130 //==== forward some methods of std::vector
136 {
137 return _data.capacity();
138 }
140 {
141 _data.resize(n,c);
142 }
144 {
145 _data.reserve(n);
146 }
147
148 //==== make this thing a vector
149 size_type size() const { return _data.size(); }
152 return _data[i];
153 }
154 const K & operator[](size_type i) const {
156 return _data[i];
157 }
158
160 K* data() noexcept
161 {
162 return _data.data();
163 }
164
166 const K* data() const noexcept
167 {
168 return _data.data();
169 }
170
171 const container_type &container () const { return _data; }
172 container_type &container () { return _data; }
173 };
174
186 template< class K, class Allocator >
189 {
191 for( typename DynamicVector< K, Allocator >::size_type i = 0; i < w.size(); ++i )
192 in >> w[ i ];
193 if(in)
194 v = std::move(w);
195 return in;
196 }
197
200} // end namespace
201
202#endif
Macro for wrapping boundary checks.
Implements a generic iterator class for writing stl conformant iterators.
Implements the dense vector interface, with an exchangeable storage class.
A few common exception classes.
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition streamoperators.hh:41
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition boundschecking.hh:28
STL namespace.
Dune namespace.
Definition alignedallocator.hh:11
Interface for a class of dense vectors over a given field.
Definition densevector.hh:227
Traits::value_type value_type
export the type representing the field
Definition densevector.hh:248
Iterator begin()
begin iterator
Definition densevector.hh:348
size_type size() const
size method
Definition densevector.hh:337
Iterator end()
end iterator
Definition densevector.hh:354
Traits::size_type size_type
The type used for the index access and size operation.
Definition densevector.hh:257
Construct a vector with a dynamic size.
Definition dynvector.hh:57
void resize(size_type n, value_type c=value_type())
Definition dynvector.hh:139
DynamicVector(const DynamicVector &x)
Constructor making vector with identical coordinates.
Definition dynvector.hh:89
Base::size_type size_type
Definition dynvector.hh:62
std::vector< K, Allocator > container_type
Definition dynvector.hh:65
size_type size() const
Definition dynvector.hh:149
K & operator[](size_type i)
Definition dynvector.hh:150
container_type & container()
Definition dynvector.hh:172
Base::value_type value_type
Definition dynvector.hh:63
const K * data() const noexcept
return pointer to underlying array
Definition dynvector.hh:166
Allocator allocator_type
Definition dynvector.hh:67
DynamicVector(const allocator_type &a=allocator_type())
Constructor making uninitialized vector.
Definition dynvector.hh:70
DynamicVector(DynamicVector &&x)
Move constructor.
Definition dynvector.hh:94
K * data() noexcept
return pointer to underlying array
Definition dynvector.hh:160
DynamicVector & operator=(DynamicVector &&other)
Move assignment operator.
Definition dynvector.hh:124
DynamicVector & operator=(const DynamicVector &other)
Copy assignment operator.
Definition dynvector.hh:117
size_type capacity() const
Number of elements for which memory has been allocated.
Definition dynvector.hh:135
const container_type & container() const
Definition dynvector.hh:171
DynamicVector(size_type n, const allocator_type &a=allocator_type())
Definition dynvector.hh:74
DynamicVector(std::initializer_list< K > const &l)
Construct from a std::initializer_list.
Definition dynvector.hh:84
DynamicVector(const DynamicVector< T, Allocator > &x)
Definition dynvector.hh:99
const K & operator[](size_type i) const
Definition dynvector.hh:154
void reserve(size_type n)
Definition dynvector.hh:143
DynamicVector(size_type n, value_type c, const allocator_type &a=allocator_type())
Constructor making vector with identical coordinates.
Definition dynvector.hh:79
DynamicVector(const DenseVector< X > &x, const allocator_type &a=allocator_type())
Copy constructor from another DenseVector.
Definition dynvector.hh:105
DynamicVector< K, Allocator > derived_type
Definition dynvector.hh:36
std::vector< K, Allocator > container_type
Definition dynvector.hh:37
container_type::size_type size_type
Definition dynvector.hh:39
FieldTraits< K >::real_type real_type
Definition dynvector.hh:46
FieldTraits< K >::field_type field_type
Definition dynvector.hh:45
Definition ftraits.hh:24
T field_type
export the type representing the field
Definition ftraits.hh:26
T real_type
export the type representing the real type of the field
Definition ftraits.hh:28
Definition matvectraits.hh:29
T capacity(T... args)
T data(T... args)
T push_back(T... args)
T reserve(T... args)
T resize(T... args)
T size(T... args)