From b084cb2e4c31524577a9bc1b5fbb32471af11201 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 15 Sep 2015 21:08:00 +1000 Subject: [PATCH] image: index operator should return references this allows the caller to use the return value's address --- image.cpp | 5 +++-- image.hpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/image.cpp b/image.cpp index a48ad4ee..2cde6f83 100644 --- a/image.cpp +++ b/image.cpp @@ -255,7 +255,7 @@ util::image::buffer::downsample (float factor) const /////////////////////////////////////////////////////////////////////////////// template -T +const T& buffer::operator[] (point<2,size_t> p) const { CHECK_LT (p.x, w); @@ -279,7 +279,7 @@ buffer::operator[] (point<2,size_t> p) //----------------------------------------------------------------------------- template -T +const T& buffer::operator[] (size_t idx) const { CHECK_LT (idx, h * s); @@ -354,6 +354,7 @@ buffer::end (void) const //----------------------------------------------------------------------------- +template struct util::image::buffer; template struct util::image::buffer; template struct util::image::buffer; template struct util::image::buffer; diff --git a/image.hpp b/image.hpp index ff134fec..3b59e5ce 100644 --- a/image.hpp +++ b/image.hpp @@ -63,10 +63,10 @@ namespace util { namespace image { //--------------------------------------------------------------------- constexpr size_t offset (point<2,size_t>) const; - T operator[] (point<2,size_t>) const; + const T& operator[] (point<2,size_t>) const; T& operator[] (point<2,size_t>); - T operator[] (size_t) const; + const T& operator[] (size_t) const; T& operator[] (size_t); //---------------------------------------------------------------------