From 5a991f3e215b2960402b68bdb81a6d1890b8e2fe Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 17 May 2015 22:51:42 +0100 Subject: [PATCH] array::in_range --- octa/array.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/octa/array.h b/octa/array.h index 325e65d..4a6f774 100644 --- a/octa/array.h +++ b/octa/array.h @@ -35,9 +35,16 @@ namespace octa { T &last() noexcept { return p_buf[N - 1]; } const T &last() const noexcept { return p_buf[N - 1]; } - bool empty() const noexcept { return (N > 0); } size_t length() const noexcept { return N; } + bool empty() const noexcept { return (N > 0); } + + bool in_range(size_t idx) noexcept { return idx < N; } + bool in_range(int idx) noexcept { return idx >= 0 && idx < N; } + bool in_range(const T *ptr) noexcept { + return ptr >= &p_buf[0] && ptr < &p_buf[p_len]; + } + T *get() noexcept { return p_buf; } const T *get() const noexcept { return p_buf; }