diff --git a/src/util/ConstBuffer.hxx b/src/util/ConstBuffer.hxx index ad795911e..eddee80e5 100644 --- a/src/util/ConstBuffer.hxx +++ b/src/util/ConstBuffer.hxx @@ -55,32 +55,33 @@ struct ConstBuffer { ConstBuffer() = default; - constexpr ConstBuffer(std::nullptr_t):data(nullptr), size(0) {} + constexpr ConstBuffer(std::nullptr_t) noexcept + :data(nullptr), size(0) {} - constexpr ConstBuffer(pointer_type _data, size_type _size) + constexpr ConstBuffer(pointer_type _data, size_type _size) noexcept :data(_data), size(_size) {} - constexpr static ConstBuffer FromVoid(ConstBuffer other) { + constexpr static ConstBuffer FromVoid(ConstBuffer other) noexcept { return other; } - constexpr ConstBuffer ToVoid() const { + constexpr ConstBuffer ToVoid() const noexcept { return *this; } - constexpr bool IsNull() const { + constexpr bool IsNull() const noexcept { return data == nullptr; } - constexpr bool operator==(std::nullptr_t) const { + constexpr bool operator==(std::nullptr_t) const noexcept { return data == nullptr; } - constexpr bool operator!=(std::nullptr_t) const { + constexpr bool operator!=(std::nullptr_t) const noexcept { return data != nullptr; } - constexpr bool empty() const { + constexpr bool empty() const noexcept { return size == 0; } }; @@ -104,26 +105,27 @@ struct ConstBuffer { ConstBuffer() = default; - constexpr ConstBuffer(std::nullptr_t):data(nullptr), size(0) {} + constexpr ConstBuffer(std::nullptr_t) noexcept + :data(nullptr), size(0) {} - constexpr ConstBuffer(pointer_type _data, size_type _size) + constexpr ConstBuffer(pointer_type _data, size_type _size) noexcept :data(_data), size(_size) {} - constexpr ConstBuffer(pointer_type _data, pointer_type _end) + constexpr ConstBuffer(pointer_type _data, pointer_type _end) noexcept :data(_data), size(_end - _data) {} /** * Convert array to ConstBuffer instance. */ template - constexpr ConstBuffer(const T (&_data)[_size]) + constexpr ConstBuffer(const T (&_data)[_size]) noexcept :data(_data), size(_size) {} /** * Cast a ConstBuffer to a ConstBuffer, rounding down * to the next multiple of T's size. */ - static constexpr ConstBuffer FromVoidFloor(ConstBuffer other) { + static constexpr ConstBuffer FromVoidFloor(ConstBuffer other) noexcept { static_assert(sizeof(T) > 0, "Empty base type"); return ConstBuffer(pointer_type(other.data), other.size / sizeof(T)); @@ -138,7 +140,7 @@ struct ConstBuffer { #ifdef NDEBUG constexpr #endif - static ConstBuffer FromVoid(ConstBuffer other) { + static ConstBuffer FromVoid(ConstBuffer other) noexcept { static_assert(sizeof(T) > 0, "Empty base type"); #ifndef NDEBUG assert(other.size % sizeof(T) == 0); @@ -146,24 +148,24 @@ struct ConstBuffer { return FromVoidFloor(other); } - constexpr ConstBuffer ToVoid() const { + constexpr ConstBuffer ToVoid() const noexcept { static_assert(sizeof(T) > 0, "Empty base type"); return ConstBuffer(data, size * sizeof(T)); } - constexpr bool IsNull() const { + constexpr bool IsNull() const noexcept { return data == nullptr; } - constexpr bool operator==(std::nullptr_t) const { + constexpr bool operator==(std::nullptr_t) const noexcept { return data == nullptr; } - constexpr bool operator!=(std::nullptr_t) const { + constexpr bool operator!=(std::nullptr_t) const noexcept { return data != nullptr; } - constexpr bool empty() const { + constexpr bool empty() const noexcept { return size == 0; } @@ -177,26 +179,26 @@ struct ConstBuffer { return false; } - constexpr iterator begin() const { + constexpr iterator begin() const noexcept { return data; } - constexpr iterator end() const { + constexpr iterator end() const noexcept { return data + size; } - constexpr const_iterator cbegin() const { + constexpr const_iterator cbegin() const noexcept { return data; } - constexpr const_iterator cend() const { + constexpr const_iterator cend() const noexcept { return data + size; } #ifdef NDEBUG constexpr #endif - reference_type operator[](size_type i) const { + reference_type operator[](size_type i) const noexcept { #ifndef NDEBUG assert(i < size); #endif @@ -211,7 +213,7 @@ struct ConstBuffer { #ifdef NDEBUG constexpr #endif - reference_type front() const { + reference_type front() const noexcept { #ifndef NDEBUG assert(!empty()); #endif @@ -225,7 +227,7 @@ struct ConstBuffer { #ifdef NDEBUG constexpr #endif - reference_type back() const { + reference_type back() const noexcept { #ifndef NDEBUG assert(!empty()); #endif @@ -236,7 +238,7 @@ struct ConstBuffer { * Remove the first element (by moving the head pointer, does * not actually modify the buffer). Buffer must not be empty. */ - void pop_front() { + void pop_front() noexcept { #ifndef NDEBUG assert(!empty()); #endif @@ -249,7 +251,7 @@ struct ConstBuffer { * Remove the last element (by moving the tail pointer, does * not actually modify the buffer). Buffer must not be empty. */ - void pop_back() { + void pop_back() noexcept { #ifndef NDEBUG assert(!empty()); #endif @@ -261,13 +263,13 @@ struct ConstBuffer { * Remove the first element and return a reference to it. * Buffer must not be empty. */ - reference_type shift() { + reference_type shift() noexcept { reference_type result = front(); pop_front(); return result; } - void skip_front(size_type n) { + void skip_front(size_type n) noexcept { #ifndef NDEBUG assert(size >= n); #endif @@ -280,7 +282,7 @@ struct ConstBuffer { * Move the front pointer to the given address, and adjust the * size attribute to retain the old end address. */ - void MoveFront(pointer_type new_data) { + void MoveFront(pointer_type new_data) noexcept { #ifndef NDEBUG assert(IsNull() == (new_data == nullptr)); assert(new_data <= end()); @@ -294,7 +296,7 @@ struct ConstBuffer { * Move the end pointer to the given address (by adjusting the * size). */ - void SetEnd(pointer_type new_end) { + void SetEnd(pointer_type new_end) noexcept { #ifndef NDEBUG assert(IsNull() == (new_end == nullptr)); assert(new_end >= begin()); diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx index 4919d8487..ae6e14af5 100644 --- a/src/util/WritableBuffer.hxx +++ b/src/util/WritableBuffer.hxx @@ -56,28 +56,29 @@ struct WritableBuffer { WritableBuffer() = default; - constexpr WritableBuffer(std::nullptr_t):data(nullptr), size(0) {} + constexpr WritableBuffer(std::nullptr_t) noexcept + :data(nullptr), size(0) {} - constexpr WritableBuffer(pointer_type _data, size_type _size) + constexpr WritableBuffer(pointer_type _data, size_type _size) noexcept :data(_data), size(_size) {} constexpr operator ConstBuffer() const noexcept { return {data, size}; } - constexpr bool IsNull() const { + constexpr bool IsNull() const noexcept { return data == nullptr; } - constexpr bool operator==(std::nullptr_t) const { + constexpr bool operator==(std::nullptr_t) const noexcept { return data == nullptr; } - constexpr bool operator!=(std::nullptr_t) const { + constexpr bool operator!=(std::nullptr_t) const noexcept { return data != nullptr; } - constexpr bool empty() const { + constexpr bool empty() const noexcept { return size == 0; } }; @@ -103,19 +104,21 @@ struct WritableBuffer { WritableBuffer() = default; - constexpr WritableBuffer(std::nullptr_t):data(nullptr), size(0) {} + constexpr WritableBuffer(std::nullptr_t) noexcept + :data(nullptr), size(0) {} - constexpr WritableBuffer(pointer_type _data, size_type _size) + constexpr WritableBuffer(pointer_type _data, size_type _size) noexcept :data(_data), size(_size) {} - constexpr WritableBuffer(pointer_type _data, pointer_type _end) + constexpr WritableBuffer(pointer_type _data, + pointer_type _end) noexcept :data(_data), size(_end - _data) {} /** * Convert array to WritableBuffer instance. */ template - constexpr WritableBuffer(T (&_data)[_size]) + constexpr WritableBuffer(T (&_data)[_size]) noexcept :data(_data), size(_size) {} constexpr operator ConstBuffer() const noexcept { @@ -126,7 +129,7 @@ struct WritableBuffer { * Cast a WritableBuffer to a WritableBuffer, * rounding down to the next multiple of T's size. */ - static constexpr WritableBuffer FromVoidFloor(WritableBuffer other) { + static constexpr WritableBuffer FromVoidFloor(WritableBuffer other) noexcept { static_assert(sizeof(T) > 0, "Empty base type"); return WritableBuffer(pointer_type(other.data), other.size / sizeof(T)); @@ -141,7 +144,7 @@ struct WritableBuffer { #ifdef NDEBUG constexpr #endif - static WritableBuffer FromVoid(WritableBuffer other) { + static WritableBuffer FromVoid(WritableBuffer other) noexcept { static_assert(sizeof(T) > 0, "Empty base type"); #ifndef NDEBUG assert(other.size % sizeof(T) == 0); @@ -149,47 +152,47 @@ struct WritableBuffer { return FromVoidFloor(other); } - constexpr WritableBuffer ToVoid() const { + constexpr WritableBuffer ToVoid() const noexcept { static_assert(sizeof(T) > 0, "Empty base type"); return WritableBuffer(data, size * sizeof(T)); } - constexpr bool IsNull() const { + constexpr bool IsNull() const noexcept { return data == nullptr; } - constexpr bool operator==(std::nullptr_t) const { + constexpr bool operator==(std::nullptr_t) const noexcept { return data == nullptr; } - constexpr bool operator!=(std::nullptr_t) const { + constexpr bool operator!=(std::nullptr_t) const noexcept { return data != nullptr; } - constexpr bool empty() const { + constexpr bool empty() const noexcept { return size == 0; } - constexpr iterator begin() const { + constexpr iterator begin() const noexcept { return data; } - constexpr iterator end() const { + constexpr iterator end() const noexcept { return data + size; } - constexpr const_iterator cbegin() const { + constexpr const_iterator cbegin() const noexcept { return data; } - constexpr const_iterator cend() const { + constexpr const_iterator cend() const noexcept { return data + size; } #ifdef NDEBUG constexpr #endif - reference_type operator[](size_type i) const { + reference_type operator[](size_type i) const noexcept { #ifndef NDEBUG assert(i < size); #endif @@ -204,7 +207,7 @@ struct WritableBuffer { #ifdef NDEBUG constexpr #endif - reference_type front() const { + reference_type front() const noexcept { #ifndef NDEBUG assert(!empty()); #endif @@ -218,7 +221,7 @@ struct WritableBuffer { #ifdef NDEBUG constexpr #endif - reference_type back() const { + reference_type back() const noexcept { #ifndef NDEBUG assert(!empty()); #endif @@ -229,7 +232,7 @@ struct WritableBuffer { * Remove the first element (by moving the head pointer, does * not actually modify the buffer). Buffer must not be empty. */ - void pop_front() { + void pop_front() noexcept { assert(!empty()); ++data; @@ -240,7 +243,7 @@ struct WritableBuffer { * Remove the last element (by moving the tail pointer, does * not actually modify the buffer). Buffer must not be empty. */ - void pop_back() { + void pop_back() noexcept { assert(!empty()); --size; @@ -250,13 +253,13 @@ struct WritableBuffer { * Remove the first element and return a reference to it. * Buffer must not be empty. */ - reference_type shift() { + reference_type shift() noexcept { reference_type result = front(); pop_front(); return result; } - void skip_front(size_type n) { + void skip_front(size_type n) noexcept { #ifndef NDEBUG assert(size >= n); #endif @@ -269,7 +272,7 @@ struct WritableBuffer { * Move the front pointer to the given address, and adjust the * size attribute to retain the old end address. */ - void MoveFront(pointer_type new_data) { + void MoveFront(pointer_type new_data) noexcept { #ifndef NDEBUG assert(IsNull() == (new_data == nullptr)); assert(new_data <= end()); @@ -283,7 +286,7 @@ struct WritableBuffer { * Move the end pointer to the given address (by adjusting the * size). */ - void SetEnd(pointer_type new_end) { + void SetEnd(pointer_type new_end) noexcept { #ifndef NDEBUG assert(IsNull() == (new_end == nullptr)); assert(new_end >= begin());