| 47 | /// |
| 48 | template<typename T, bsl::uintmx N> |
| 49 | class basic_queue_t final |
| 50 | { |
| 51 | /// @brief stores a circular buffer for the queue. |
| 52 | bsl::array<T, N> m_queue{}; |
| 53 | /// @brief stores the head of the queue. |
| 54 | bsl::safe_idx m_head{}; |
| 55 | /// @brief stores the tail of the queue. |
| 56 | bsl::safe_idx m_tail{}; |
| 57 | |
| 58 | public: |
| 59 | /// @brief alias for: T |
| 60 | using value_type = T; |
| 61 | /// @brief alias for: safe_umx |
| 62 | using size_type = bsl::safe_umx; |
| 63 | /// @brief alias for: safe_idx |
| 64 | using index_type = bsl::safe_idx; |
| 65 | /// @brief alias for: safe_umx |
| 66 | using difference_type = bsl::safe_umx; |
| 67 | /// @brief alias for: T & |
| 68 | using reference_type = T &; |
| 69 | /// @brief alias for: T const & |
| 70 | using const_reference_type = T const &; |
| 71 | /// @brief alias for: T * |
| 72 | using pointer_type = T *; |
| 73 | /// @brief alias for: T const * |
| 74 | using const_pointer_type = T const *; |
| 75 | |
| 76 | /// <!-- description --> |
| 77 | /// @brief Pushes an element to the queue and returns |
| 78 | /// bsl::errc_success. If the queue is full, returns |
| 79 | /// bsl::errc_failure. |
| 80 | /// |
| 81 | /// <!-- inputs/outputs --> |
| 82 | /// @param val the value to push to the queue |
| 83 | /// @param sloc the source location of the push for debugging |
| 84 | /// @return Returns bsl::errc_success on success, or |
| 85 | /// bsl::errc_failure if the queue is full. |
| 86 | /// |
| 87 | [[nodiscard]] constexpr auto |
| 88 | push(T const &val, bsl::source_location const &sloc = bsl::here()) noexcept |
| 89 | -> bsl::errc_type |
| 90 | { |
| 91 | if (bsl::unlikely(this->full())) { |
| 92 | bsl::error() << "queue is full\n" << sloc; |
| 93 | return bsl::errc_failure; |
| 94 | } |
| 95 | |
| 96 | *m_queue.at_if(m_head) = val; |
| 97 | |
| 98 | ++m_head; |
| 99 | if (m_head >= N) { |
| 100 | m_head = {}; |
| 101 | } |
| 102 | else { |
| 103 | bsl::touch(); |
| 104 | } |
| 105 | |
| 106 | return bsl::errc_success; |
nothing calls this directly
no outgoing calls
no test coverage detected