8
8
Vector
9
9
******
10
10
11
- Vectors are resizeable arrays of elements. All vectors support the following
12
- basic operations.
11
+ Vectors are resizeable arrays of elements. The ``flc_vector `` module
12
+ instantiates vectors of ``integer(4) ``, ``integer(8) ``, ``real(8) ``, and
13
+ ``type(String) ``.
14
+
15
+ Common functionality
16
+ ====================
17
+
18
+ All vector types support the following basic operations.
13
19
14
20
Construction and destruction
15
21
----------------------------
@@ -77,6 +83,14 @@ The size of a vector is returned by the bound function ``size``; ``get``
77
83
returns the value at an index; and ``front `` and ``back `` are aliases for
78
84
``get(1) `` and ``get(v%size()) ``, respectively.
79
85
86
+ Additionally, ``front_ref ``, ``back_ref ``, and ``get_ref `` return pointers to
87
+ the elements of the array.
88
+
89
+ .. warning :: Array element pointers are valid **only** as long as the vector's
90
+ size is not changed. Calling ``erase ``, ``push_back ``, and so forth will
91
+ invalidate the pointer; accessing it at that point results in undefined
92
+ behavior.
93
+
80
94
Numeric vectors
81
95
===============
82
96
@@ -100,6 +114,8 @@ an array pointer::
100
114
v = Vector(iarr)
101
115
write(0,*) "Size should be 4:", v%size()
102
116
117
+ The ``assign `` bound method acts like a constructor but for an existing vector.
118
+
103
119
View as an array pointer
104
120
------------------------
105
121
@@ -124,7 +140,20 @@ underlying memory as the C++ object::
124
140
String vectors
125
141
==============
126
142
127
- String vectors are not yet implemented.
143
+ String vectors' native "element" type is a ``character(len=:) ``. Vector
144
+ operations that accept an input will take any native character string; and
145
+ returned values will be allocatable character arrays.
146
+
147
+ The ``front_ref ``, ``back_ref ``, and ``get_ref `` functions allow the underlying
148
+ ``std::string `` class to be accessed with the ``String `` Fortran derived type
149
+ wrapper. Note that unlike for intrinsic types, where these functions return a
150
+ ``integer, pointer ``, the vector of strings returns just ``type(String) ``.
151
+ However, as with native pointers described above, these references are
152
+ *invalid * once the string changes size. They should be cleared with the
153
+ ``%release() `` bound method.
154
+
155
+ An additional ``set_ref `` function allows vector elements to be assigned from
156
+ vector classes.
128
157
129
158
.. ############################################################################
130
159
.. end of doc/modules/vector.rst
0 commit comments