view: prefer std::next over std::advance

next is slightly less likely to trigger issues dereferencing a temporary
(since we aren't producing an lvalue).
This commit is contained in:
Danny Robson 2018-05-08 21:49:27 +10:00
parent e7c108c770
commit 34fc834a29
2 changed files with 3 additions and 9 deletions

View File

@ -80,9 +80,7 @@ namespace util {
iterator operator+ (int count) iterator operator+ (int count)
{ {
auto next = *this; return std::next (*this, count);
std::advance (next, count);
return next;
} }
const range_type& operator* (void) const const range_type& operator* (void) const

View File

@ -356,18 +356,14 @@ namespace util {
constexpr auto& constexpr auto&
operator[] (size_t idx)& noexcept operator[] (size_t idx)& noexcept
{ {
auto it = begin (); return *std::next (begin (), idx);
std::advance (it, idx);
return *it;
} }
//--------------------------------------------------------------------- //---------------------------------------------------------------------
constexpr auto& constexpr auto&
operator[] (size_t idx) const& noexcept operator[] (size_t idx) const& noexcept
{ {
auto it = begin (); return *std::next (begin (), idx);
std::advance (it, idx);
return *it;
} }
private: private: