Skip to content

Commit

Permalink
Merge pull request #491 from devosoft/mmore500-array-iteratortraits
Browse files Browse the repository at this point in the history
Add iterator traits to emp::array iterator and fixes conversions to spans for Bits.
  • Loading branch information
mercere99 authored Dec 1, 2023
2 parents 8132567 + 6ad7a5d commit 4e402f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/emp/base/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ namespace emp {
using this_t = array_iterator<ITERATOR_T, ARRAY_T>;
using array_t = ARRAY_T;

// Iterator traits
using iterator_category = typename std::iterator_traits<ITERATOR_T>::iterator_category;
using value_type = typename std::iterator_traits<ITERATOR_T>::value_type;
using difference_type = typename std::iterator_traits<ITERATOR_T>::difference_type;
using pointer = typename std::iterator_traits<ITERATOR_T>::pointer;
using reference = typename std::iterator_traits<ITERATOR_T>::reference;

ITERATOR_T it;
const array_t * arr_ptr { nullptr }; // Which array was iterator created from?

Expand Down
4 changes: 2 additions & 2 deletions include/emp/bits/Bits_Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ namespace emp {
}
}

[[nodiscard]] auto AsSpan() { return std::span<field_t,MAX_FIELDS>(bits.data()); }
[[nodiscard]] auto AsSpan() const { return std::span<const field_t,MAX_FIELDS>(bits.data()); }
[[nodiscard]] auto AsSpan() { return std::span<field_t,MAX_FIELDS>(bits.data(), MAX_FIELDS); }
[[nodiscard]] auto AsSpan() const { return std::span<const field_t,MAX_FIELDS>(bits.data(), MAX_FIELDS); }

[[nodiscard]] bool OK() const { return true; } // Nothing to check yet.

Expand Down

0 comments on commit 4e402f3

Please sign in to comment.