Skip to content

Commit 9c2f33e

Browse files
Make contiguous_iterator constexpr iterator
Per [optional.iterators]/1 and the proposed [optionalref.iterators]/1 in P2988R7. Rough test: https://godbolt.org/z/7eEhh954W
1 parent 4c5cd80 commit 9c2f33e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/beman/optional26/detail/iterator.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ struct contiguous_iterator : public base_contiguous_iterator<T, Container> {
4343
using typename base_type::reference;
4444

4545
// Default constructor.
46-
contiguous_iterator() noexcept : m_current() {}
46+
constexpr contiguous_iterator() noexcept : m_current() {}
4747

4848
// Pointer to iterator constructor.
49-
contiguous_iterator(pointer it) noexcept : m_current(it) {}
49+
constexpr contiguous_iterator(pointer it) noexcept : m_current(it) {}
5050

5151
// As per P2727R4, for contiguous iterator we only need to provide operator*, operator+= and operator-.
52-
reference operator*() const noexcept { return *m_current; }
53-
auto& operator+=(difference_type pos) noexcept {
52+
constexpr reference operator*() const noexcept { return *m_current; }
53+
constexpr auto& operator+=(difference_type pos) noexcept {
5454
m_current += pos;
5555
return *this;
5656
}
57-
difference_type operator-(contiguous_iterator other) const noexcept { return m_current - other.m_current; }
57+
constexpr difference_type operator-(contiguous_iterator other) const noexcept {
58+
return m_current - other.m_current;
59+
}
5860

5961
private:
6062
T* m_current;

0 commit comments

Comments
 (0)