diff options
Diffstat (limited to 'src/include/iterator')
-rw-r--r-- | src/include/iterator | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/src/include/iterator b/src/include/iterator index 396e1b594..dbd712b9e 100644 --- a/src/include/iterator +++ b/src/include/iterator @@ -5,7 +5,9 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* COPYRIGHT International Business Machines Corp. 2012,2014 */ +/* Contributors Listed Below - COPYRIGHT 2012,2019 */ +/* [+] International Business Machines Corp. */ +/* */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); */ /* you may not use this file except in compliance with the License. */ @@ -62,11 +64,11 @@ struct iterator_traits<T*> * @param[in] i - The iterator to advance. * @param[in] n - The distance to advance the iterator. * - * This function is equivalent to calling (++i) n times. + * This function is equivalent to calling (++i) n times. * - * If the iterator supports random access then this function will be + * If the iterator supports random access then this function will be * implemented in linear time with respect to n. - * + * */ template <typename InputIterator, typename Distance> void advance(InputIterator& i, Distance n) @@ -90,11 +92,11 @@ void advance(InputIterator& i, Distance n) * access iterators. */ template <typename InputIterator> -typename iterator_traits<InputIterator>::difference_type +typename iterator_traits<InputIterator>::difference_type distance(InputIterator first, InputIterator last) { return Util::__Util_Iterator_Impl::distance< - InputIterator, + InputIterator, typename iterator_traits<InputIterator>::difference_type> (first, last); } @@ -129,7 +131,7 @@ class back_insert_iterator /** Dereference operator. * * This is used to make the standard pattern '*i = x' work on - * an iterator. Since we need to 'push_back' into the + * an iterator. Since we need to 'push_back' into the * container we don't actually return anything except ourself, * which allows the operator= to be called. */ @@ -168,16 +170,44 @@ class back_insert_iterator * copy(v.rbegin(), v.rend(), back_inserter(v2)); * * @param[in] s - Sequence to create an iterator for. - * + * * @return The back_insert_iterator. */ template <typename BackInsertionSequence> -back_insert_iterator<BackInsertionSequence> +back_insert_iterator<BackInsertionSequence> back_inserter(BackInsertionSequence& s) { return back_insert_iterator<BackInsertionSequence>(s); } +/** + * begin(array) + * Returns pointer to beginning of array + * + * Example: + * int c_array[] = {0, 1, 2}; + * vector<int> l_cpp_array (begin(c_array), end(c_array)); + */ +template <typename T, size_t size> +T* begin(T (&c_array)[size]) +{ + return &c_array[0]; +} + +/** + * end(array) + * Returns pointer to end of array (i.e. the element after the last element) + * + * Example: + * int c_array[] = {0, 1, 2}; + * vector<int> l_cpp_array (begin(c_array), end(c_array)); + */ +template <typename T, size_t size> +T* end(T (&c_array)[size]) +{ + return &c_array[0] + size; +} + }; // namespace std. #endif |