@@ -109,14 +109,14 @@ struct ConstSliceBase : SliceBase {
109109 /* !
110110 * Obtain a constant iterator to the first element in the slice.
111111 */
112- const_iterator cbegin () const noexcept {
112+ [[nodiscard]] const_iterator cbegin () const noexcept {
113113 return storage_.unsafeGetIteratorAt (begin_);
114114 }
115115
116116 /* !
117117 * Obtain a constant iterator to the first beyond the slice.
118118 */
119- const_iterator cend () const noexcept {
119+ [[nodiscard]] const_iterator cend () const noexcept {
120120 return storage_.unsafeGetIteratorAt (end_);
121121 }
122122
@@ -129,7 +129,7 @@ struct ConstSliceBase : SliceBase {
129129 * mutable_slice_base.
130130 */
131131 template <typename slice_type>
132- slice_type subSlice (size_t begin, size_t end) const {
132+ [[nodiscard]] slice_type subSlice (size_t begin, size_t end) const {
133133 this ->rangeCheck (begin);
134134 // end == size() is a legal value, since end is the first
135135 // element beyond the slice
@@ -219,8 +219,8 @@ struct MutableSliceBase : public ConstSliceBase<storage_type, data_type> {
219219 * the appropriate `slice<const T>` and call its `subSlice() const`,
220220 * which returns the correct type.
221221 */
222- ConstSliceBase<storage_type, const data_type> to_const_base () const noexcept {
223- return ConstSliceBase<storage_type, const data_type>( this ->storage_ .data_ , this ->begin_ , this ->end_ ) ;
222+ [[nodiscard]] ConstSliceBase<storage_type, const data_type> to_const_base () const noexcept {
223+ return { this ->storage_ .data_ , this ->begin_ , this ->end_ } ;
224224 }
225225
226226 using base_type = ConstSliceBase<storage_type, data_type>;
@@ -281,11 +281,11 @@ struct ContainerStorage {
281281 *
282282 * @throw whatever container::at() throws
283283 */
284- const value_type& unsafeAt (size_t index) const {
284+ [[nodiscard]] const value_type& unsafeAt (size_t index) const {
285285 return data_.at (index);
286286 }
287287
288- value_type& unsafeAt (size_t index) {
288+ [[nodiscard]] value_type& unsafeAt (size_t index) {
289289 return data_.at (index);
290290 }
291291
@@ -295,19 +295,19 @@ struct ContainerStorage {
295295 *
296296 * @throw whatever container::begin() and std::advance() throw
297297 */
298- iterator unsafeGetIteratorAt (size_t index) {
298+ [[nodiscard]] iterator unsafeGetIteratorAt (size_t index) {
299299 // we are screwed if the container got changed => try to catch it
300300 assert (index <= data_.size ());
301301
302- iterator it = data_.begin ();
302+ auto it = data_.begin ();
303303 std::advance (it, index);
304304 return it;
305305 }
306306
307- const_iterator unsafeGetIteratorAt (size_t index) const {
307+ [[nodiscard]] const_iterator unsafeGetIteratorAt (size_t index) const {
308308 assert (index <= data_.size ());
309309
310- const_iterator it = data_.begin ();
310+ auto it = data_.begin ();
311311 std::advance (it, index);
312312 return it;
313313 }
@@ -346,11 +346,11 @@ struct PtrSliceStorage {
346346 *
347347 * @throw nothing
348348 */
349- value_type& unsafeAt (size_t index) noexcept {
349+ [[nodiscard]] value_type& unsafeAt (size_t index) noexcept {
350350 return data_[index];
351351 }
352352
353- const value_type& unsafeAt (size_t index) const noexcept {
353+ [[nodiscard]] const value_type& unsafeAt (size_t index) const noexcept {
354354 return data_[index];
355355 }
356356
@@ -360,11 +360,11 @@ struct PtrSliceStorage {
360360 *
361361 * @throw nothing
362362 */
363- iterator unsafeGetIteratorAt (size_t index) noexcept {
363+ [[nodiscard]] iterator unsafeGetIteratorAt (size_t index) noexcept {
364364 return data_ + index;
365365 }
366366
367- const_iterator unsafeGetIteratorAt (size_t index) const noexcept {
367+ [[nodiscard]] const_iterator unsafeGetIteratorAt (size_t index) const noexcept {
368368 return data_ + index;
369369 }
370370
@@ -462,7 +462,7 @@ struct Slice : public Internal::MutableSliceBase<Internal::ContainerStorage, con
462462 * Constructs a new constant subSlice. Behaves otherwise exactly like
463463 * the non-const version.
464464 */
465- Slice<const container> subSlice (size_t begin, size_t end) const {
465+ [[nodiscard]] Slice<const container> subSlice (size_t begin, size_t end) const {
466466 return this ->to_const_base ().template subSlice <Slice<const container>>(begin, end);
467467 }
468468};
@@ -534,7 +534,7 @@ struct Slice<T*> : public Internal::MutableSliceBase<Internal::PtrSliceStorage,
534534 return Internal::MutableSliceBase<Internal::PtrSliceStorage, T*>::template subSlice<Slice<T*>>(begin, end);
535535 }
536536
537- Slice<const T*> subSlice (size_t begin, size_t end) const {
537+ [[nodiscard]] Slice<const T*> subSlice (size_t begin, size_t end) const {
538538 return this ->to_const_base ().template subSlice <Slice<const T*>>(begin, end);
539539 }
540540};
0 commit comments