From c22760a232ca2168d02f913e0ddb9d72407ef5f6 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Tue, 19 Jul 2011 00:26:05 -0700 Subject: [PATCH] add operator[] overload --- src/root/root.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/root/root.h b/src/root/root.h index 1f980ae60b28..bac6036e648d 100644 --- a/src/root/root.h +++ b/src/root/root.h @@ -1,6 +1,6 @@ -// Copyright (c) 1999-2010 by Digital Mars +// Copyright (c) 1999-2011 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com @@ -13,6 +13,9 @@ #include #include +#ifdef DEBUG +#include +#endif #if __DMC__ #pragma once @@ -353,12 +356,20 @@ struct ArrayBase : Array return (TYPE **)data; } - void insert(unsigned index, TYPE *v) + TYPE*& operator[] (size_t index) + { +#ifdef DEBUG + assert(index < dim); +#endif + return ((TYPE **)data)[index]; + } + + void insert(size_t index, TYPE *v) { Array::insert(index, (void *)v); } - void insert(unsigned index, ArrayBase *a) + void insert(size_t index, ArrayBase *a) { Array::insert(index, (Array *)a); }