Skip to content

Commit

Permalink
base() const &&
Browse files Browse the repository at this point in the history
owning::base() const && = delete to sometimes avoid accidental copy.
For presumably cheap to copy cases, we want to always return by value from rvalue object, even if it is const
  • Loading branch information
OleErikPeistorpet committed May 30, 2024
1 parent 7a8f42d commit 9a999e9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions view/move.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class _moveView
OEL_REQUIRES(iter_is_random_access< iterator_t<View> >) OEL_ALWAYS_INLINE { return begin()[index]; }

constexpr View base() && { return std::move(_base); }
constexpr View base() const && { return _base; }
constexpr const View & base() const & noexcept { return _base; }
};

Expand Down
5 changes: 3 additions & 2 deletions view/owning.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class owning
constexpr decltype(auto) operator[](difference_type index)
OEL_REQUIRES(iter_is_random_access< iterator_t<Range> >) { return adl_begin(_r)[index]; }

constexpr Range && base() && noexcept { return std::move(_r); }
constexpr const Range & base() const & noexcept { return _r; }
constexpr Range base() && { return std::move(_r); }
constexpr const Range & base() const & noexcept { return _r; }
void base() const && = delete;
};

}
Expand Down
1 change: 1 addition & 0 deletions view/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class _transformView
constexpr bool empty() { return _m.first.empty(); }

constexpr View base() && { return std::move(_m.first); }
constexpr View base() const && { return _m.first; }
constexpr const View & base() const & noexcept { return _m.first; }
};

Expand Down
1 change: 1 addition & 0 deletions view/transform_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class transform_iterator
constexpr transform_iterator(UnaryFunc f, Iterator it) : _m{std::move(it), std::move(f)} {}

constexpr Iterator base() && { return std::move(_m.first); }
constexpr Iterator base() const && { return _m.first; }
constexpr const Iterator & base() const & noexcept OEL_ALWAYS_INLINE { return _m.first; }

constexpr reference operator*() const
Expand Down

0 comments on commit 9a999e9

Please sign in to comment.