fork download
  1. #include <iostream>
  2. #include <cstdint>
  3. #include <complex>
  4.  
  5. // class to hold various data types
  6. template <typename T>
  7. class DataArray
  8. {
  9. public:
  10. DataArray(){};
  11. T *ptr;
  12. };
  13.  
  14. // Processing configuration
  15. template <typename T>
  16. class Config
  17. {
  18. public:
  19. Config(){};
  20. T var;
  21. };
  22.  
  23. namespace helper {
  24.  
  25. template<typename T>
  26. struct value_type_of {
  27. using type = T;
  28. };
  29.  
  30. template<typename T>
  31. struct value_type_of<std::complex<T>> {
  32. using type = typename std::complex<T>::value_type;
  33. //or simply: using type = T;
  34. };
  35. }
  36.  
  37. // The data processor itself, takes input, output array and the processing configuration
  38. template <typename Tin, typename Tout>
  39. class Process
  40. {
  41. public:
  42. using ConfigType = Config<typename helper::value_type_of<Tout>::type>;
  43.  
  44. DataArray<Tin> *in;
  45. DataArray<Tout> *out;
  46. ConfigType *config;
  47.  
  48. Process(){};
  49. Process(DataArray<Tin> *in_, DataArray<Tout> *out_, ConfigType *config_)
  50. {
  51. in = in_;
  52. out = out_;
  53. config = config_;
  54. }
  55. };
  56.  
  57. void Real2Real()
  58. {
  59. DataArray<int16_t> input;
  60. DataArray<float> output;
  61. Config<float> config;
  62. // real 2 real processing
  63. Process<int16_t, float> P1(&input, &output, &config); // works fine
  64. }
  65.  
  66. void Real2Complex()
  67. {
  68. DataArray<int16_t> input;
  69. DataArray<std::complex<float>> output;
  70. Config<float> config;
  71.  
  72. // real 2 complex processing
  73. Process<int16_t, std::complex<float>> P2(&input, &output, &config); // Obviously does not work
  74. }
  75.  
  76. int main() {
  77. Real2Real();
  78. Real2Complex();
  79. return 0;
  80. }
Success #stdin #stdout 0.01s 5384KB
stdin
Standard input is empty
stdout
Standard output is empty