gslcpp
Modern-C++ Wrapper for GSL
include
gslcpp
doc
d-vector.hpp
Go to the documentation of this file.
1
/// \file include/gslcpp/doc/d-vector.hpp
2
/// \brief Narrative documentation for gsl::vector.
3
/// \copyright 2022 Thomas E. Vaughan, all rights reserved.
4
5
/// \page d_vector About gsl::vector
6
///
7
/// The template-class gsl::vector is one of two descendants of gsl::v_iface.
8
///
9
/// The other is gsl::vector_view.
10
///
11
/// gsl::vector exists to provide constructors for gsl::v_iface.
12
///
13
/// - gsl::vector provides no interface other than construction.
14
///
15
/// - gsl::v_iface provides almost all of the interfaces that GSL's native
16
/// vector provides.
17
///
18
/// - Any instance constructed via one of the template-specializations of
19
/// gsl::vector owns memory allocated both for the elements in the vector and
20
/// for some metadata referring to that memory.
21
///
22
///
23
/// ## Dynamic Allocation of Memory
24
///
25
/// For any element-type `T` (`double`, `float`, `complex<long double>`, etc.),
26
/// any instance of `gsl::vector<T,0>` has the number of elements determined at
27
/// run-time.
28
///
29
/// - Internally, construction involves a call
30
/// - to `gsl_vector_alloc()` or
31
/// - to `gsl_vector_calloc()`.
32
///
33
/// - The pointer returned is stored on the stack inside the instance.
34
///
35
/// - There is also on the stack a pointer to the virtual-function table.
36
/// - The ultimate base-class gsl::v_stor<T>, which manages the pointer, has
37
/// a virtual destructor.
38
///
39
///
40
/// ## Static Allocation of Memory
41
///
42
/// For any element-type `T` and positive compile-time integer `N`, any
43
/// instance of `gsl::vector<T,N>` has the number of elements determined at
44
/// compile-time.
45
///
46
/// - Internally, the elements are allocated on the stack in a C-style array.
47
///
48
/// - The return-value of `gsl_vector_view_array()` is also stored on the
49
/// stack in the instance of gsl::vector.
50
/// - The instance of `gsl_vector_view` returned by `gsl_vector_view_array()`
51
/// consumes about 40 bytes on a 64-bit machine.
52
///
53
/// - There is on the stack no pointer to the virtual-function table.
54
/// - There is no virtual destructor in the inheritance-chain.
55
///
56
///
57
/// ## Example
58
///
59
/// The template-parameters to gsl::vector often need not be specified because
60
/// they are deduced by the compiler.
61
///
62
/// Here is an example-program:
63
/// \include vector-example.cpp
64
///
65
/// And here is its output:
66
/// \include vector-example.out
67
///
68
///
69
/// ## Move-Construction
70
///
71
/// The move-constructor is also defined for `gsl::vector<T>`, and so one could
72
/// also do something like this:
73
///
74
/// ~~~{.cpp}
75
/// #include <gsl/vector.hpp>
76
///
77
/// using gsl::vector;
78
///
79
/// vector<float,0> read_big_file_into_array();
80
///
81
/// int main() {
82
/// vector v= read_big_file_into_array();
83
/// return 0;
84
/// }
85
/// ~~~
86
///
87
/// In compiling the code above, the compiler,
88
///
89
/// - *might* elide the constructor-call in the installation of the
90
/// return-value from `read_big_file_into_array()` into `v`, but
91
///
92
/// - is not *required* to elide the call (according to C++-17), depending on
93
/// how the vector inside the function is obtained.
94
///
95
/// However, even if the compiler do not elide the call to a constructor, the
96
/// big array would still not be *copied* into `v` because there is
97
/// a move-constructor that would be called.
98
99
// EOF
Generated on Mon Mar 14 2022 00:01:27 for gslcpp by
1.8.17