From f919983e03874f95967b422e0259aed1dfa7d79e Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 21 May 2015 00:34:42 +0100 Subject: [PATCH] array fixes --- octa/array.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/octa/array.h b/octa/array.h index f490876..2f74a37 100644 --- a/octa/array.h +++ b/octa/array.h @@ -8,6 +8,7 @@ #include +#include "octa/algorithm.h" #include "octa/range.h" namespace octa { @@ -32,8 +33,8 @@ namespace octa { T &first() { return p_buf[0]; } const T &first() const { return p_buf[0]; } - T &last() { return p_buf[N - 1]; } - const T &last() const { return p_buf[N - 1]; } + T &last() { return p_buf[(N > 0) ? (N - 1) : 0]; } + const T &last() const { return p_buf[(N > 0) ? (N - 1) : 0]; } size_t length() const { return N; } @@ -48,10 +49,6 @@ namespace octa { T *get() { return p_buf; } const T *get() const { return p_buf; } - void swap(Array &v)(swap(declval(), declval())) { - swap(p_buf, v.p_buf); - } - RangeType each() { return PointerRange(p_buf, p_buf + N); } @@ -59,7 +56,11 @@ namespace octa { return PointerRange(p_buf, p_buf + N); } - T p_buf[N]; + void swap(Array &v) { + swap_ranges(each(), v.each()); + } + + T p_buf[(N > 0) ? N : 1]; }; template