From 582ed66b307ef514742cd6c6cb5f50affe771699 Mon Sep 17 00:00:00 2001 From: Matt Derksen Date: Thu, 22 Aug 2019 09:21:13 -0500 Subject: 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 Tested-by: Jenkins OP Build CI Tested-by: FSP CI Jenkins Tested-by: Jenkins OP HW Reviewed-by: Christian R Geddes Reviewed-by: Glenn Miles Reviewed-by: Nicholas E Bofferding --- src/usr/testcore/lib/stltest.H | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/usr/testcore') diff --git a/src/usr/testcore/lib/stltest.H b/src/usr/testcore/lib/stltest.H index 31cc3cbe9..34cb64d4a 100644 --- a/src/usr/testcore/lib/stltest.H +++ b/src/usr/testcore/lib/stltest.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2011,2017 */ +/* Contributors Listed Below - COPYRIGHT 2011,2019 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -782,5 +782,35 @@ class STLTest : public CxxTest::TestSuite } } + /// Test std::begin() and std::end() on base-type array + void testBaseTypeBeginEnd() + { + const int MAX_ENTRIES = 1025; + int baseA[MAX_ENTRIES] = {0}; // base-type array + + // Initialize base array to known values + for (int i = 0; i < MAX_ENTRIES; i++) + { + baseA[i] = i; + } + + // use std::begin() and std::end() to copy base-type array to vector + std::vector baseV ( std::begin(baseA), std::end(baseA)); + + if (baseV.size() != MAX_ENTRIES) + { + TS_FAIL("testBaseTypeBeginEnd: expected %d elements, found %d in vector", + MAX_ENTRIES, baseV.size()); + } + + for (int i = 0; i < MAX_ENTRIES; i++) + { + if (baseA[i] != baseV[i]) + { + TS_FAIL("testBaseTypeBeginEnd: No match at index %d (base %d vs vector %d)", + i, baseA[i], baseV[i]); + } + } + } }; #endif -- cgit v1.2.3