gslcpp
Modern-C++ Wrapper for GSL
container.hpp
Go to the documentation of this file.
1 /// \dir include/gslcpp/wrap
2 /// \brief C++-wrapper for each native C-type and function in GSL.
3 
4 /// \file include/gslcpp/wrap/container.hpp
5 /// \copyright 2022 Thomas E. Vaughan, all rights reserved.
6 ///
7 /// \brief Definition of
8 /// gsl::container,
9 /// \ref w_vector,
10 /// \ref w_vector_view,
11 /// \ref w_matrix,
12 /// \ref w_matrix_view.
13 
14 #pragma once
15 
16 #ifndef HAVE_INLINE
17 /// Indicate that the inline-definition of each function in GSL should used.
18 /// `HAVE_INLINE` should be defined *before* the inclusion of `gsl_vector.h`.
19 # define HAVE_INLINE
20 #endif
21 
22 #include "complex.hpp" // gsl::complex
23 #include <gsl/gsl_matrix.h> // gsl_matrix, gsl_matrix_float, etc.
24 #include <gsl/gsl_vector.h> // gsl_vector, gsl_vector_float, etc.
25 
26 namespace gsl {
27 
28 
29 /// For type E of element, define type of each vector, matrix, and view.
30 /// @tparam E Type of each element in vector or matrix.
31 template<typename E> struct container;
32 
33 
34 /// Specialization for double.
35 /// \sa \ref container
36 template<> struct container<double> {
37  using vector= gsl_vector; ///< GSL's native type for vector.
38  using vector_view= gsl_vector_view; ///< GSL's native type for vector-view.
39  using matrix= gsl_matrix; ///< GSL's native type for matrix.
40  using matrix_view= gsl_matrix_view; ///< GSL's native type for matrix-view.
41 };
42 
43 
44 /// Specialization for double const.
45 /// \sa \ref container
46 template<> struct container<double const> {
47  /// GSL's native type for vector.
48  using vector= gsl_vector const;
49 
50  /// GSL's native type for vector-view.
51  using vector_view= gsl_vector_const_view;
52 
53  /// GSL's native type for matrix.
54  using matrix= gsl_matrix const;
55 
56  /// GSL's native type for matrix-view.
57  using matrix_view= gsl_matrix_const_view;
58 };
59 
60 
61 /// Specialization for float.
62 /// \sa \ref container
63 template<> struct container<float> {
64  /// GSL's native type for vector.
65  using vector= gsl_vector_float;
66 
67  /// GSL's native type for vector-view.
68  using vector_view= gsl_vector_float_view;
69 
70  /// GSL's native type for matrix.
71  using matrix= gsl_matrix_float;
72 
73  /// GSL's native type for matrix-view.
74  using matrix_view= gsl_matrix_float_view;
75 };
76 
77 
78 /// Specialization for float const.
79 /// \sa \ref container
80 template<> struct container<float const> {
81  /// GSL's native type for vector.
82  using vector= gsl_vector_float const;
83 
84  /// GSL's native type for vector-view.
85  using vector_view= gsl_vector_float_const_view;
86 
87  /// GSL's native type for matrix.
88  using matrix= gsl_matrix_float const;
89 
90  /// GSL's native type for matrix-view.
91  using matrix_view= gsl_matrix_float_const_view;
92 };
93 
94 
95 /// Specialization for long double.
96 /// \sa \ref container
97 template<> struct container<long double> {
98  /// GSL's native type for vector.
99  using vector= gsl_vector_long_double;
100 
101  /// GSL's native type for vector-view.
102  using vector_view= gsl_vector_long_double_view;
103 
104  /// GSL's native type for matrix.
105  using matrix= gsl_matrix_long_double;
106 
107  /// GSL's native type for matrix-view.
108  using matrix_view= gsl_matrix_long_double_view;
109 };
110 
111 
112 /// Specialization for long double const.
113 /// \sa \ref container
114 template<> struct container<long double const> {
115  /// GSL's native type for vector.
116  using vector= gsl_vector_long_double const;
117 
118  /// GSL's native type for vector-view.
119  using vector_view= gsl_vector_long_double_const_view;
120 
121  /// GSL's native type for matrix.
122  using matrix= gsl_matrix_long_double const;
123 
124  /// GSL's native type for matrix-view.
125  using matrix_view= gsl_matrix_long_double_const_view;
126 };
127 
128 
129 /// Specialization for int.
130 /// \sa \ref container
131 template<> struct container<int> {
132  /// GSL's native type for vector.
133  using vector= gsl_vector_int;
134 
135  /// GSL's native type for vector-view.
136  using vector_view= gsl_vector_int_view;
137 
138  /// GSL's native type for matrix.
139  using matrix= gsl_matrix_int;
140 
141  /// GSL's native type for matrix-view.
142  using matrix_view= gsl_matrix_int_view;
143 };
144 
145 
146 /// Specialization for int const.
147 /// \sa \ref container
148 template<> struct container<int const> {
149  /// GSL's native type for vector.
150  using vector= gsl_vector_int const;
151 
152  /// GSL's native type for vector-view
153  using vector_view= gsl_vector_int_const_view;
154 
155  /// GSL's native type for matrix.
156  using matrix= gsl_matrix_int const;
157 
158  /// GSL's native type for matrix-view.
159  using matrix_view= gsl_matrix_int_const_view;
160 };
161 
162 
163 /// Specialization for unsigned.
164 /// \sa \ref container
165 template<> struct container<unsigned> {
166  /// GSL's native type for vector.
167  using vector= gsl_vector_uint;
168 
169  /// GSL's native type for vector-view.
170  using vector_view= gsl_vector_uint_view;
171 
172  /// GSL's native type for matrix.
173  using matrix= gsl_matrix_uint;
174 
175  /// GSL's native type for matrix-view.
176  using matrix_view= gsl_matrix_uint_view;
177 };
178 
179 
180 /// Specialization for unsigned const.
181 /// \sa \ref container
182 template<> struct container<unsigned const> {
183  /// GSL's native type for vector.
184  using vector= gsl_vector_uint const;
185 
186  /// GSL's native type for vector-view.
187  using vector_view= gsl_vector_uint_const_view;
188 
189  /// GSL's native type for matrix.
190  using matrix= gsl_matrix_uint const;
191 
192  /// GSL's native type for matrix-view.
193  using matrix_view= gsl_matrix_uint_const_view;
194 };
195 
196 
197 /// Specialization for long.
198 /// \sa \ref container
199 template<> struct container<long> {
200  /// GSL's native type for vector.
201  using vector= gsl_vector_long;
202 
203  /// GSL's native type for vector-view.
204  using vector_view= gsl_vector_long_view;
205 
206  /// GSL's native type for matrix.
207  using matrix= gsl_matrix_long;
208 
209  /// GSL's native type for matrix-view.
210  using matrix_view= gsl_matrix_long_view;
211 };
212 
213 
214 /// Specialization for long const.
215 /// \sa \ref container
216 template<> struct container<long const> {
217  /// GSL's native type for vector.
218  using vector= gsl_vector_long const;
219 
220  /// GSL's native type for vector-view.
221  using vector_view= gsl_vector_long_const_view;
222 
223  /// GSL's native type for matrix.
224  using matrix= gsl_matrix_long const;
225 
226  /// GSL's native type for matrix-view.
227  using matrix_view= gsl_matrix_long_const_view;
228 };
229 
230 
231 /// Specialization for unsigned long.
232 /// \sa \ref container
233 template<> struct container<unsigned long> {
234  /// GSL's native type for vector.
235  using vector= gsl_vector_ulong;
236 
237  /// GSL's native type for vector-view.
238  using vector_view= gsl_vector_ulong_view;
239 
240  /// GSL's native type for matrix.
241  using matrix= gsl_matrix_ulong;
242 
243  /// GSL's native type for matrix-view.
244  using matrix_view= gsl_matrix_ulong_view;
245 };
246 
247 
248 /// Specialization for unsigned long const.
249 /// \sa \ref container
250 template<> struct container<unsigned long const> {
251  /// GSL's native type for vector.
252  using vector= gsl_vector_ulong const;
253 
254  /// GSL's native type for vector-view.
255  using vector_view= gsl_vector_ulong_const_view;
256 
257  /// GSL's native type for matrix.
258  using matrix= gsl_matrix_ulong const;
259 
260  /// GSL's native type for matrix-view.
261  using matrix_view= gsl_matrix_ulong_const_view;
262 };
263 
264 
265 /// Specialization for short.
266 /// \sa \ref container
267 template<> struct container<short> {
268  /// GSL's native type for vector.
269  using vector= gsl_vector_short;
270 
271  /// GSL's native type for vector-view.
272  using vector_view= gsl_vector_short_view;
273 
274  /// GSL's native type for matrix.
275  using matrix= gsl_matrix_short;
276 
277  /// GSL's native type for matrix-view.
278  using matrix_view= gsl_matrix_short_view;
279 };
280 
281 
282 /// Specialization for short const.
283 /// \sa \ref container
284 template<> struct container<short const> {
285  /// GSL's native type for vector.
286  using vector= gsl_vector_short const;
287 
288  /// GSL's native type for vector-view.
289  using vector_view= gsl_vector_short_const_view;
290 
291  /// GSL's native type for matrix.
292  using matrix= gsl_matrix_short const;
293 
294  /// GSL's native type for matrix-view.
295  using matrix_view= gsl_matrix_short_const_view;
296 };
297 
298 
299 /// Specialization for unsigned short.
300 /// \sa \ref container
301 template<> struct container<unsigned short> {
302  /// GSL's native type for vector.
303  using vector= gsl_vector_ushort;
304 
305  /// GSL's native type for vector-view.
306  using vector_view= gsl_vector_ushort_view;
307 
308  /// GSL's native type for matrix.
309  using matrix= gsl_matrix_ushort;
310 
311  /// GSL's native type for matrix-view.
312  using matrix_view= gsl_matrix_ushort_view;
313 };
314 
315 
316 /// Specialization for unsigned short const.
317 /// \sa \ref container
318 template<> struct container<unsigned short const> {
319  /// GSL's native type for vector.
320  using vector= gsl_vector_ushort const;
321 
322  /// GSL's native type for vector-view.
323  using vector_view= gsl_vector_ushort_const_view;
324 
325  /// GSL's native type for matrix.
326  using matrix= gsl_matrix_ushort const;
327 
328  /// GSL's native type for matrix-view.
329  using matrix_view= gsl_matrix_ushort_const_view;
330 };
331 
332 
333 /// Specialization for char.
334 /// \sa \ref container
335 template<> struct container<char> {
336  /// GSL's native type for vector.
337  using vector= gsl_vector_char;
338 
339  /// GSL's native type for vector-view.
340  using vector_view= gsl_vector_char_view;
341 
342  /// GSL's native type for matrix.
343  using matrix= gsl_matrix_char;
344 
345  /// GSL's native type for matrix-view.
346  using matrix_view= gsl_matrix_char_view;
347 };
348 
349 
350 /// Specialization for char const.
351 /// \sa \ref container
352 template<> struct container<char const> {
353  /// GSL's native type for vector.
354  using vector= gsl_vector_char const;
355 
356  /// GSL's native type for vector-view.
357  using vector_view= gsl_vector_char_const_view;
358 
359  /// GSL's native type for matrix.
360  using matrix= gsl_matrix_char const;
361 
362  /// GSL's native type for matrix-view.
363  using matrix_view= gsl_matrix_char_const_view;
364 };
365 
366 
367 /// Specialization for unsigned char.
368 /// \sa \ref container
369 template<> struct container<unsigned char> {
370  /// GSL's native type for vector.
371  using vector= gsl_vector_uchar;
372 
373  /// GSL's native type for vector-view.
374  using vector_view= gsl_vector_uchar_view;
375 
376  /// GSL's native type for matrix.
377  using matrix= gsl_matrix_uchar;
378 
379  /// GSL's native type for matrix-view.
380  using matrix_view= gsl_matrix_uchar_view;
381 };
382 
383 
384 /// Specialization for unsigned char const.
385 /// \sa \ref container
386 template<> struct container<unsigned char const> {
387  /// GSL's native type for vector.
388  using vector= gsl_vector_uchar const;
389 
390  /// GSL's native type for vector-view.
391  using vector_view= gsl_vector_uchar_const_view;
392 
393  /// GSL's native type for matrix.
394  using matrix= gsl_matrix_uchar const;
395 
396  /// GSL's native type for matrix-view.
397  using matrix_view= gsl_matrix_uchar_const_view;
398 };
399 
400 
401 /// Specialization for gsl_complex.
402 /// \sa \ref container
403 template<> struct container<complex<double>> {
404  /// GSL's native type for vector.
405  using vector= gsl_vector_complex;
406 
407  /// GSL's native type for vector-view.
408  using vector_view= gsl_vector_complex_view;
409 
410  /// GSL's native type for matrix.
411  using matrix= gsl_matrix_complex;
412 
413  /// GSL's native type for matrix-view.
414  using matrix_view= gsl_matrix_complex_view;
415 };
416 
417 
418 /// Specialization for gsl_complex const.
419 /// \sa \ref container
420 template<> struct container<complex<double> const> {
421  /// GSL's native type for vector.
422  using vector= gsl_vector_complex const;
423 
424  /// GSL's native type for vector-view.
425  using vector_view= gsl_vector_complex_const_view;
426 
427  /// GSL's native type for matrix.
428  using matrix= gsl_matrix_complex const;
429 
430  /// GSL's native type for matrix-view.
431  using matrix_view= gsl_matrix_complex_const_view;
432 };
433 
434 
435 /// Specialization for gsl_complex_float.
436 /// \sa \ref container
437 template<> struct container<complex<float>> {
438  /// GSL's native type for vector.
439  using vector= gsl_vector_complex_float;
440 
441  /// GSL's native type for vector.
442  using vector_view= gsl_vector_complex_float_view;
443 
444  /// GSL's native type for matrix.
445  using matrix= gsl_matrix_complex_float;
446 
447  /// GSL's native type for matrix-view.
448  using matrix_view= gsl_matrix_complex_float_view;
449 };
450 
451 
452 /// Specialization for gsl_complex_float const.
453 /// \sa \ref container
454 template<> struct container<complex<float> const> {
455  /// GSL's native type for vector.
456  using vector= gsl_vector_complex_float const;
457 
458  /// GSL's native type for vector.
459  using vector_view= gsl_vector_complex_float_const_view;
460 
461  /// GSL's native type for matrix.
462  using matrix= gsl_matrix_complex_float const;
463 
464  /// GSL's native type for matrix-view.
465  using matrix_view= gsl_matrix_complex_float_const_view;
466 };
467 
468 
469 /// Specialization for gsl_complex_long_double.
470 /// \sa \ref container
471 template<> struct container<complex<long double>> {
472  /// GSL's native type for vector.
473  using vector= gsl_vector_complex_long_double;
474 
475  /// GSL's native type for vector.
476  using vector_view= gsl_vector_complex_long_double_view;
477 
478  /// GSL's native type for matrix.
479  using matrix= gsl_matrix_complex_long_double;
480 
481  /// GSL's native type for matrix-view.
482  using matrix_view= gsl_matrix_complex_long_double_view;
483 };
484 
485 
486 /// Specialization for gsl_complex_long_double const.
487 /// \sa \ref container
488 template<> struct container<complex<long double> const> {
489  /// GSL's native type for vector.
490  using vector= gsl_vector_complex_long_double const;
491 
492  /// GSL's native type for vector.
493  using vector_view= gsl_vector_complex_long_double_const_view;
494 
495  /// GSL's native type for matrix.
496  using matrix= gsl_matrix_complex_long_double const;
497 
498  /// GSL's native type for matrix-view.
499  using matrix_view= gsl_matrix_complex_long_double_const_view;
500 };
501 
502 
503 /// GSL's native vector-type corresponding to element-type `E`.
504 /// \anchor w_vector
505 /// @tparam E Type of element for vector.
506 template<typename E> using w_vector= typename container<E>::vector;
507 
508 
509 /// GSL's native view of vector corresponding to element-type `E`.
510 /// \anchor w_vector_view
511 /// @tparam E Type of element for vector.
512 template<typename E> using w_vector_view= typename container<E>::vector_view;
513 
514 
515 /// GSL's native matrix-type corresponding to element-type `E`.
516 /// \anchor w_matrix
517 /// @tparam E Type of element for matrix.
518 template<typename E> using w_matrix= typename container<E>::matrix;
519 
520 
521 /// GSL's native view of matrix corresponding to element-type `E`.
522 /// \anchor w_matrix_view
523 /// @tparam E Type of element for matrix.
524 template<typename E> using w_matrix_view= typename container<E>::matrix_view;
525 
526 
527 } // namespace gsl
528 
529 // EOF
gsl
Namespace for C++-interface to GSL.
Definition: v-iface.hpp:51