Skip to content

Commit e789ac1

Browse files
committed
Fix iterator CI portability
1 parent 4a9fe64 commit e789ac1

4 files changed

Lines changed: 79 additions & 163 deletions

File tree

include/gsl/dyn_array

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ namespace details
5454
}
5555

5656
GSL_CONSTEXPR_SINCE_CPP20 void destroy(pointer ptr)
57-
{
58-
std::allocator_traits<Allocator>::destroy(static_cast<Allocator&>(*this), ptr);
59-
}
57+
{ std::allocator_traits<Allocator>::destroy(static_cast<Allocator&>(*this), ptr); }
6058

6159
GSL_CONSTEXPR_SINCE_CPP20 void destroy_range(pointer first, pointer last)
6260
{
@@ -137,19 +135,15 @@ namespace details
137135
public:
138136
constexpr dyn_array_base(const Allocator& alloc)
139137
: Allocator{alloc}, _data{nullptr}, _count{0}
140-
{
141-
Ensures((_count == 0 && _data == nullptr) || (_count > 0 && _data != nullptr));
142-
}
138+
{ Ensures((_count == 0 && _data == nullptr) || (_count > 0 && _data != nullptr)); }
143139

144140
constexpr dyn_array_base(size_type count, const Allocator& alloc)
145141
: Allocator{alloc}
146142
, _data{count == 0 ? nullptr
147143
: std::allocator_traits<Allocator>::allocate(
148144
static_cast<Allocator&>(*this), count)}
149145
, _count{count}
150-
{
151-
Ensures((_count == 0 && _data == nullptr) || (_count > 0 && _data != nullptr));
152-
}
146+
{ Ensures((_count == 0 && _data == nullptr) || (_count > 0 && _data != nullptr)); }
153147

154148
GSL_CONSTEXPR_SINCE_CPP20 ~dyn_array_base()
155149
{
@@ -214,57 +208,43 @@ namespace details
214208
constexpr operator pointer() const { return _ptr + gsl::narrow<size_type>(_pos); }
215209
#endif /* defined(_MSC_VER) && __cpp_lib_ranges >= 201911L */
216210

217-
template <typename U,
218-
std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value, bool> =
219-
true>
211+
template <typename U, std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value,
212+
bool> = true>
220213
constexpr auto operator==(const dyn_array_iterator<U>& other) const
221214
{
222215
Expects(_ptr == other._ptr);
223216
Expects(_end_pos == other._end_pos);
224217
return _pos == other._pos;
225218
}
226219

227-
template <typename U,
228-
std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value, bool> =
229-
true>
220+
template <typename U, std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value,
221+
bool> = true>
230222
constexpr auto operator!=(const dyn_array_iterator<U>& other) const
231-
{
232-
return !(*this == other);
233-
}
223+
{ return !(*this == other); }
234224

235-
template <typename U,
236-
std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value, bool> =
237-
true>
225+
template <typename U, std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value,
226+
bool> = true>
238227
constexpr auto operator<(const dyn_array_iterator<U>& other) const
239228
{
240229
Expects(_ptr == other._ptr);
241230
Expects(_end_pos == other._end_pos);
242231
return _pos < other._pos;
243232
}
244233

245-
template <typename U,
246-
std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value, bool> =
247-
true>
234+
template <typename U, std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value,
235+
bool> = true>
248236
constexpr auto operator>(const dyn_array_iterator<U>& other) const
249-
{
250-
return other < *this;
251-
}
237+
{ return other < *this; }
252238

253-
template <typename U,
254-
std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value, bool> =
255-
true>
239+
template <typename U, std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value,
240+
bool> = true>
256241
constexpr auto operator<=(const dyn_array_iterator<U>& other) const
257-
{
258-
return !(other < *this);
259-
}
242+
{ return !(other < *this); }
260243

261-
template <typename U,
262-
std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value, bool> =
263-
true>
244+
template <typename U, std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value,
245+
bool> = true>
264246
constexpr auto operator>=(const dyn_array_iterator<U>& other) const
265-
{
266-
return !(*this < other);
267-
}
247+
{ return !(*this < other); }
268248

269249
constexpr auto operator*() const -> reference
270250
{
@@ -324,23 +304,21 @@ namespace details
324304
}
325305

326306
friend constexpr auto operator+(difference_type diff, const dyn_array_iterator& other)
327-
{
328-
return other + diff;
329-
}
307+
{ return other + diff; }
330308

331309
constexpr auto operator-(difference_type diff) const { return *this + (-diff); }
332310

333-
template <typename U,
334-
std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value, bool> =
335-
true>
311+
template <typename U, std::enable_if_t<std::is_same<std::remove_cv_t<U>, value_type>::value,
312+
bool> = true>
336313
constexpr auto operator-(const dyn_array_iterator<U>& other) const
337314
{
338315
Expects(_ptr == other._ptr);
339316
Expects(_end_pos == other._end_pos);
340317
return gsl::narrow<difference_type>(_pos) - gsl::narrow<difference_type>(other._pos);
341318
}
342319

343-
constexpr auto operator[](difference_type diff) const -> reference { return *(*this + diff); }
320+
constexpr auto operator[](difference_type diff) const -> reference
321+
{ return *(*this + diff); }
344322

345323
private:
346324
pointer _ptr{};
@@ -375,17 +353,13 @@ public:
375353

376354
constexpr dyn_array(size_type count, const T& value, const Allocator& alloc = {})
377355
: base{count, alloc}
378-
{
379-
base::fill(data(), size(), value);
380-
}
356+
{ base::fill(data(), size(), value); }
381357

382358
template <typename InputIt,
383359
std::enable_if_t<details::is_fwd_iterator<InputIt>::value, bool> = true>
384360
constexpr dyn_array(InputIt first, InputIt last, const Allocator& alloc = {})
385361
: base{gsl::narrow<size_type>(std::distance(first, last)), alloc}
386-
{
387-
base::copy(first, last, data());
388-
}
362+
{ base::copy(first, last, data()); }
389363

390364
template <typename InputIt, std::enable_if_t<!details::is_fwd_iterator<InputIt>::value &&
391365
details::is_iterator<InputIt>::value,
@@ -402,15 +376,11 @@ public:
402376
requires(std::ranges::input_range<InputRg>)
403377
constexpr dyn_array(std::from_range_t, InputRg&& rg, const Allocator& alloc = {})
404378
: base{gsl::narrow<size_type>(std::size(rg)), alloc}
405-
{
406-
base::copy(std::ranges::begin(rg), std::ranges::end(rg), data());
407-
}
379+
{ base::copy(std::ranges::begin(rg), std::ranges::end(rg), data()); }
408380
#endif /* __cpp_lib_containers_ranges >= 202202L */
409381

410382
constexpr explicit dyn_array(size_type count, const Allocator& alloc = {}) : base{count, alloc}
411-
{
412-
base::default_construct(data(), size());
413-
}
383+
{ base::default_construct(data(), size()); }
414384

415385
constexpr dyn_array(const dyn_array& other, const Allocator& alloc = {})
416386
: dyn_array(other.begin(), other.end(), alloc)
@@ -424,9 +394,7 @@ public:
424394
dyn_array& operator=(dyn_array&&) = delete;
425395

426396
constexpr auto operator==(const dyn_array& other) const
427-
{
428-
return size() == other.size() && std::equal(begin(), end(), other.begin(), other.end());
429-
}
397+
{ return size() == other.size() && std::equal(begin(), end(), other.begin(), other.end()); }
430398

431399
constexpr auto operator!=(const dyn_array& other) const { return !(*this == other); }
432400

@@ -445,9 +413,7 @@ public:
445413
}
446414

447415
constexpr auto operator[](size_type pos) const -> const_reference
448-
{
449-
return const_cast<dyn_array&>(*this)[pos];
450-
}
416+
{ return const_cast<dyn_array&>(*this)[pos]; }
451417

452418
constexpr auto data() { return base::data(); }
453419
constexpr auto data() const -> const T* { return const_cast<dyn_array&>(*this).data(); }
@@ -463,13 +429,11 @@ public:
463429
#ifdef _MSC_VER
464430
constexpr auto _Unchecked_begin() { return data(); }
465431
constexpr auto _Unchecked_begin() const -> const T*
466-
{
467-
return const_cast<dyn_array&>(*this)._Unchecked_begin();
468-
}
432+
{ return const_cast<dyn_array&>(*this)._Unchecked_begin(); }
469433
#endif /* _MSC_VER */
470434

471-
constexpr auto end() { return begin() + size(); }
472-
constexpr auto end() const { return begin() + size(); }
435+
constexpr auto end() { return begin() + gsl::narrow_cast<difference_type>(size()); }
436+
constexpr auto end() const { return begin() + gsl::narrow_cast<difference_type>(size()); }
473437
constexpr auto cend() const { return end(); }
474438

475439
constexpr auto rend() { return reverse_iterator{begin()}; }
@@ -479,9 +443,7 @@ public:
479443
#ifdef _MSC_VER
480444
constexpr auto _Unchecked_end() { return data() + size(); }
481445
constexpr auto _Unchecked_end() const -> const T*
482-
{
483-
return const_cast<dyn_array&>(*this)._Unchecked_end();
484-
}
446+
{ return const_cast<dyn_array&>(*this)._Unchecked_end(); }
485447
#endif /* _MSC_VER */
486448
};
487449

0 commit comments

Comments
 (0)