summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorMatt Derksen <mderkse1@us.ibm.com>2019-08-22 09:21:13 -0500
committerNicholas E Bofferding <bofferdn@us.ibm.com>2019-09-05 16:13:51 -0500
commit582ed66b307ef514742cd6c6cb5f50affe771699 (patch)
treee481dca81dfd8f1a46365da48056e695bab3fdf2 /src/include
parentf7dab51ab5057e622495c5762ac3ba12b6d8b59f (diff)
downloadtalos-hostboot-582ed66b307ef514742cd6c6cb5f50affe771699.tar.gz
talos-hostboot-582ed66b307ef514742cd6c6cb5f50affe771699.zip
Implement std::begin() and std::end() for base types
begin() returns an iterator to first element in array. end() returns an iterator to one past the last element in array. Change-Id: Idf97d3fbcf361f8318b84aa95452fd4fa5809d6b Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/82665 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com> Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com> Reviewed-by: Christian R Geddes <crgeddes@us.ibm.com> Reviewed-by: Glenn Miles <milesg@ibm.com> Reviewed-by: Nicholas E Bofferding <bofferdn@us.ibm.com>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/iterator48
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
OpenPOWER on IntegriCloud