gslcpp
Modern-C++ Wrapper for GSL
vector-alloc.hpp
Go to the documentation of this file.
1 /// \file include/gslcpp/wrap/vector-alloc.hpp
2 /// \copyright 2022 Thomas E. Vaughan, all rights reserved.
3 /// \brief Definition of gsl::w_vector_alloc<E>(size_t).
4 
5 #pragma once
6 #include "container.hpp" // w_vector
7 
8 namespace gsl {
9 
10 
11 /// Generic template-declaration for function that allocates vector whose
12 /// element-type is E.
13 ///
14 /// @tparam E Type of each element in vector.
15 /// @param n Number of elements to allocate.
16 /// @return Pointer to GSL's native C-struct for vector.
17 template<typename E> w_vector<E> *w_vector_alloc(size_t n);
18 
19 
20 /// Specialization for double.
21 /// @param n Number of elements to allocate.
22 /// @return Pointer to GSL's native C-struct for vector.
23 template<> inline w_vector<double> *w_vector_alloc<double>(size_t n) {
24  return gsl_vector_alloc(n);
25 }
26 
27 
28 /// Specialization for float.
29 /// @param n Number of elements to allocate.
30 /// @return Pointer to GSL's native C-struct for vector.
31 template<> inline w_vector<float> *w_vector_alloc<float>(size_t n) {
32  return gsl_vector_float_alloc(n);
33 }
34 
35 
36 /// Specialization for long double.
37 /// @param n Number of elements to allocate.
38 /// @return Pointer to GSL's native C-struct for vector.
39 template<>
40 inline w_vector<long double> *w_vector_alloc<long double>(size_t n) {
41  return gsl_vector_long_double_alloc(n);
42 }
43 
44 
45 /// Specialization for int.
46 /// @param n Number of elements to allocate.
47 /// @return Pointer to GSL's native C-struct for vector.
48 template<> inline w_vector<int> *w_vector_alloc<int>(size_t n) {
49  return gsl_vector_int_alloc(n);
50 }
51 
52 
53 /// Specialization for unsigned.
54 /// @param n Number of elements to allocate.
55 /// @return Pointer to GSL's native C-struct for vector.
56 template<> inline w_vector<unsigned> *w_vector_alloc<unsigned>(size_t n) {
57  return gsl_vector_uint_alloc(n);
58 }
59 
60 
61 /// Specialization for long.
62 /// @param n Number of elements to allocate.
63 /// @return Pointer to GSL's native C-struct for vector.
64 template<> inline w_vector<long> *w_vector_alloc<long>(size_t n) {
65  return gsl_vector_long_alloc(n);
66 }
67 
68 
69 /// Specialization for unsigned long.
70 /// @param n Number of elements to allocate.
71 /// @return Pointer to GSL's native C-struct for vector.
72 template<>
73 inline w_vector<unsigned long> *w_vector_alloc<unsigned long>(size_t n) {
74  return gsl_vector_ulong_alloc(n);
75 }
76 
77 
78 /// Specialization for short.
79 /// @param n Number of elements to allocate.
80 /// @return Pointer to GSL's native C-struct for vector.
81 template<> inline w_vector<short> *w_vector_alloc<short>(size_t n) {
82  return gsl_vector_short_alloc(n);
83 }
84 
85 
86 /// Specialization for unsigned short.
87 /// @param n Number of elements to allocate.
88 /// @return Pointer to GSL's native C-struct for vector.
89 template<>
90 inline w_vector<unsigned short> *w_vector_alloc<unsigned short>(size_t n) {
91  return gsl_vector_ushort_alloc(n);
92 }
93 
94 
95 /// Specialization for char.
96 /// @param n Number of elements to allocate.
97 /// @return Pointer to GSL's native C-struct for vector.
98 template<> inline w_vector<char> *w_vector_alloc<char>(size_t n) {
99  return gsl_vector_char_alloc(n);
100 }
101 
102 
103 /// Specialization for unsigned char.
104 /// @param n Number of elements to allocate.
105 /// @return Pointer to GSL's native C-struct for vector.
106 template<>
107 inline w_vector<unsigned char> *w_vector_alloc<unsigned char>(size_t n) {
108  return gsl_vector_uchar_alloc(n);
109 }
110 
111 
112 /// Specialization for complex<double>.
113 /// @param n Number of elements to allocate.
114 /// @return Pointer to GSL's native C-struct for vector.
115 template<>
116 inline w_vector<complex<double>> *w_vector_alloc<complex<double>>(size_t n) {
117  return gsl_vector_complex_alloc(n);
118 }
119 
120 
121 /// Specialization for complex<float>.
122 /// @param n Number of elements to allocate.
123 /// @return Pointer to GSL's native C-struct for vector.
124 template<>
125 inline w_vector<complex<float>> *w_vector_alloc<complex<float>>(size_t n) {
126  return gsl_vector_complex_float_alloc(n);
127 }
128 
129 
130 /// Specialization for complex<long double>.
131 /// @param n Number of elements to allocate.
132 /// @return Pointer to GSL's native C-struct for vector.
133 template<>
134 inline w_vector<complex<long double>> *
135 w_vector_alloc<complex<long double>>(size_t n) {
136  return gsl_vector_complex_long_double_alloc(n);
137 }
138 
139 
140 } // namespace gsl
141 
142 // EOF
gsl::w_vector_alloc
w_vector< E > * w_vector_alloc(size_t n)
Generic template-declaration for function that allocates vector whose element-type is E.
gsl
Namespace for C++-interface to GSL.
Definition: v-iface.hpp:51