Sirius  0.0.0
types.h
Go to the documentation of this file.
1 
22 #ifndef SIRIUS_FFTW_TYPES_H_
23 #define SIRIUS_FFTW_TYPES_H_
24 
25 #include <memory>
26 
27 #include <fftw3.h>
28 
29 #include "sirius/utils/log.h"
30 
31 namespace sirius {
32 namespace fftw {
33 
34 namespace detail {
35 
40  void operator()(::fftw_complex* complex) {
41  if (complex == nullptr) {
42  return;
43  }
44  ::fftw_free(complex);
45  }
46 };
47 
51 struct RealDeleter {
52  void operator()(double* real) { ::fftw_free(real); }
53 };
54 
55 } // namespace detail
56 
57 using ComplexUPtr = std::unique_ptr<::fftw_complex[], detail::ComplexDeleter>;
58 
59 #if (!defined(__GNUC__) && __cplusplus <= 201402L) || \
60  (defined(__GNUC__) && __GNUC__ < 7 && __cplusplus <= 201402L)
61 
62 // C++14: no shared_ptr array syntax, classic definition
63 using ComplexSPtr = std::shared_ptr<::fftw_complex>;
64 
65 #else
66 
67 // C++17: std::shared_ptr array syntax
68 
69 // compiling with GCC7 breaks the build if C++14 syntax is used
70 // definition of std::shared_ptr<T>::element_type has changed:
71 // <7: typedef _Tp element_type;
72 // >=7: using element_type = typename remove_extent<_Tp>::type;
73 // With GCC <7:
74 // std::shared_ptr<double[2]>::element_type <=> double[2]
75 // With GCC >=7:
76 // std::shared_ptr<double[2]>::element_type <=> double
77 // std::shared_ptr<double[][2]>::element_type <=> double[2]
78 
79 using ComplexSPtr = std::shared_ptr<::fftw_complex[]>;
80 
81 #endif // (!defined(__GNUC__) && __cplusplus <= 201402L) ||
82  // (defined(__GNUC__) && __GNUC__ < 7 && __cplusplus <= 201402L)
83 
84 using RealUPtr = std::unique_ptr<double[], detail::RealDeleter>;
85 
86 } // namespace fftw
87 } // namespace sirius
88 
89 #endif // SIRIUS_FFTW_TYPES_H_
Definition: exception.h:27
void operator()(double *real)
Definition: types.h:52
std::shared_ptr<::fftw_complex > ComplexSPtr
Definition: types.h:63
void operator()(::fftw_complex *complex)
Definition: types.h:40
std::unique_ptr<::fftw_complex[], detail::ComplexDeleter > ComplexUPtr
Definition: types.h:57
Deleter of fftw_complex array for smart pointer.
Definition: types.h:39
std::unique_ptr< double[], detail::RealDeleter > RealUPtr
Definition: types.h:84
Deleter of fftw real array for smart pointer.
Definition: types.h:51