From fc2f73c6295f42a912e1130725ee70ca49e426fc Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Mon, 8 Dec 2014 20:24:41 +0000 Subject: [PATCH] Added cbegin, cend, rbegin, rend, crbegin, crend --- container.h | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 145 insertions(+), 4 deletions(-) diff --git a/container.h b/container.h index c36d0d1b..22f85e3a 100644 --- a/container.h +++ b/container.h @@ -29,7 +29,8 @@ SOFTWARE. #ifndef __ETL_CONTAINER__ #define __ETL_CONTAINER__ -#include +#include +#include ///\defgroup container container ///\ingroup utilities @@ -56,6 +57,36 @@ namespace etl return container.begin(); } + //***************************************************************************** + /// Get the 'begin' const_iterator for a container. + ///\ingroup container + //***************************************************************************** + template + typename TContainer::const_iterator cbegin(const TContainer& container) + { + return container.cbegin(); + } + + //***************************************************************************** + /// Get the 'begin' reverse_iterator for a container. + ///\ingroup container + //***************************************************************************** + template + typename TContainer::reverse_iterator rbegin(const TContainer& container) + { + return container.rbegin(); + } + + //***************************************************************************** + /// Get the 'begin' reverse_iterator for a container. + ///\ingroup container + //***************************************************************************** + template + typename TContainer::reverse_iterator crbegin(const TContainer& container) + { + return container.crbegin(); + } + //***************************************************************************** /// Get the 'end' iterator for a container. ///\ingroup container @@ -76,16 +107,86 @@ namespace etl return container.end(); } + //***************************************************************************** + /// Get the 'end' const_iterator for a container. + ///\ingroup container + //***************************************************************************** + template + typename TContainer::const_iterator cend(const TContainer& container) + { + return container.cend(); + } + + //***************************************************************************** + /// Get the 'end' reverse_iterator for a container. + ///\ingroup container + //***************************************************************************** + template + typename TContainer::const_iterator rend(const TContainer& container) + { + return container.rend(); + } + + //***************************************************************************** + /// Get the 'end' reverse_iterator for a container. + ///\ingroup container + //***************************************************************************** + template + typename TContainer::reverse_iterator crend(const TContainer& container) + { + return container.crend(); + } + //***************************************************************************** - /// Get the 'begin' iterator for an array. + /// Get the 'begin' pointer for an array. ///\ingroup container //***************************************************************************** template TValue* begin(TValue(&data)[ARRAY_SIZE]) { - return (&data[0]); + return &data[0]; } + //***************************************************************************** + /// Get the 'begin' const iterator for an array. + ///\ingroup container + //***************************************************************************** + template + const TValue* begin(const TValue(&data)[ARRAY_SIZE]) + { + return &data[0]; + } + + //***************************************************************************** + /// Get the 'begin' const iterator for an array. + ///\ingroup container + //***************************************************************************** + template + const TValue* cbegin(const TValue(&data)[ARRAY_SIZE]) + { + return &data[0]; + } + + //***************************************************************************** + /// Get the 'begin' reverse_iterator for an array. + ///\ingroup container + //***************************************************************************** + template + std::reverse_iterator rbegin(const TValue(&data)[ARRAY_SIZE]) + { + return std::reverse_iterator(&data[ARRAY_SIZE]); + } + + //***************************************************************************** + /// Get the 'begin' const reverse_iterator for an array. + ///\ingroup container + //***************************************************************************** + template + std::reverse_iterator crbegin(const TValue(&data)[ARRAY_SIZE]) + { + return std::reverse_iterator(&data[ARRAY_SIZE]); + } + //***************************************************************************** /// Get the 'end' iterator for an array. ///\ingroup container @@ -93,9 +194,49 @@ namespace etl template TValue* end(TValue(&data)[ARRAY_SIZE]) { - return (&data[ARRAY_SIZE]); + return &data[ARRAY_SIZE]; } + //***************************************************************************** + /// Get the 'end' const iterator for an array. + ///\ingroup container + //***************************************************************************** + template + const TValue* end(const TValue(&data)[ARRAY_SIZE]) + { + return &data[ARRAY_SIZE]; + } + + //***************************************************************************** + /// Get the 'end' const iterator for an array. + ///\ingroup container + //***************************************************************************** + template + const TValue* cend(const TValue(&data)[ARRAY_SIZE]) + { + return &data[ARRAY_SIZE]; + } + + //***************************************************************************** + /// Get the 'end' reverse_iterator for an array. + ///\ingroup container + //***************************************************************************** + template + std::reverse_iterator rend(const TValue(&data)[ARRAY_SIZE]) + { + return std::reverse_iterator(&data[0]); + } + + //***************************************************************************** + /// Get the 'end' const reverse_iterator for an array. + ///\ingroup container + //***************************************************************************** + template + std::reverse_iterator crend(const TValue(&data)[ARRAY_SIZE]) + { + return std::reverse_iterator(&data[0]); + } + //***************************************************************************** /// Get the next iterator. ///\ingroup container