fork download
  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4.  
  5. constexpr auto MAX_NUM_RETURNLETS_ALL_CHAN_ONE_SITE = 18;
  6.  
  7. enum Chan : uint8_t
  8. {
  9. HIGH_NEAR = 0, ///< High gain near channel
  10. HIGH_FAR, ///< High gain far channel
  11. SUPER_LOW, ///< Super low gain channel
  12. NUM_CHANNELS_PER_SITE ///< Total number of channels per site
  13. };
  14.  
  15. /// Lightweight index into SoA calibrated returns - used during sort/filter to minimize memory traffic
  16. struct SortedIndex
  17. {
  18. Chan gc; ///< The gain channel of the returnlet
  19. std::uint8_t idx; ///< Index within the channel's SoA
  20. std::uint8_t site; ///< The site of this returnlet
  21. };
  22.  
  23. /// The sort function effectively flattens the multi-channel returns into a single array of returnlets with their associated gain channel.
  24. // struct SortedReturnlet
  25. // {
  26. // CalibratedReturn returnlet; ///< The returnlet to be sorted
  27. // std::uint8_t site; ///< The site of this returnlet
  28. // Chan gc; ///< The gain channel of the returnlet
  29. // };
  30.  
  31. /// Arrays for sorted indices and returnlets
  32. using SortedIndices = std::array<SortedIndex, MAX_NUM_RETURNLETS_ALL_CHAN_ONE_SITE>;
  33.  
  34. int main() {
  35. // your code goes here
  36. SortedIndices sorted_indices; // Uninitialized
  37. auto sorted_idx_it = begin(sorted_indices);
  38. auto const end_sorted_indices = end(sorted_indices);
  39. cout << "Array start: " << sorted_indices.data() << endl;
  40. cout << "Iterator addr: " << &(*sorted_idx_it) << endl;
  41. cout << "End - begin: " << end_sorted_indices - sorted_idx_it << endl;
  42. sorted_idx_it++;
  43. cout << "Array index 1: " << sorted_indices.data() + 1 << endl;
  44. cout << "Iterator addr 1: " << &(*sorted_idx_it) << endl;
  45. cout << "End - begin: " << end_sorted_indices - sorted_idx_it << endl;
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Array start: 0x7ffcd9f8fcd0
Iterator addr: 0x7ffcd9f8fcd0
End - begin: 18
Array index 1: 0x7ffcd9f8fcd3
Iterator addr 1: 0x7ffcd9f8fcd3
End - begin: 17