From 34fc834a298930d0759a79767f03a85e2055b1c2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 8 May 2018 21:49:27 +1000 Subject: [PATCH] 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). --- string.hpp | 4 +--- view.hpp | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/string.hpp b/string.hpp index f113d2cf..195be093 100644 --- a/string.hpp +++ b/string.hpp @@ -80,9 +80,7 @@ namespace util { iterator operator+ (int count) { - auto next = *this; - std::advance (next, count); - return next; + return std::next (*this, count); } const range_type& operator* (void) const diff --git a/view.hpp b/view.hpp index 9e2240e0..99a88aad 100644 --- a/view.hpp +++ b/view.hpp @@ -356,18 +356,14 @@ namespace util { constexpr auto& operator[] (size_t idx)& noexcept { - auto it = begin (); - std::advance (it, idx); - return *it; + return *std::next (begin (), idx); } //--------------------------------------------------------------------- constexpr auto& operator[] (size_t idx) const& noexcept { - auto it = begin (); - std::advance (it, idx); - return *it; + return *std::next (begin (), idx); } private: