Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/GSL.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorericLemanissier <ericLemanissier@users.noreply.github.com>2016-05-09 14:02:27 +0300
committerericLemanissier <eric.lemanissier@gmail.com>2016-05-09 16:27:17 +0300
commit9d8866a732a9c2da79079fbd73bb2b933a6af5af (patch)
treeeaf2603407efcb6373845f40c190b9c675ca2fa3 /tests/at_tests.cpp
parenta9f865900d28b854de5ead971aadb82e5ef9ed40 (diff)
gsl::at overload for initializer_list
initializer_list do not have subscript operator, so the generic container overload of gsl::at fails to compile. This commits adds an overload of gsl::at for initializer_lists, using *(initializer_list::begin()+index) instead of subscript operator
Diffstat (limited to 'tests/at_tests.cpp')
-rw-r--r--tests/at_tests.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/at_tests.cpp b/tests/at_tests.cpp
index d27dd9d..1a9f814 100644
--- a/tests/at_tests.cpp
+++ b/tests/at_tests.cpp
@@ -17,6 +17,7 @@
#include <UnitTest++/UnitTest++.h>
#include <gsl.h>
#include <vector>
+#include <initializer_list>
using namespace std;
using namespace gsl;
@@ -52,6 +53,16 @@ SUITE(at_tests)
CHECK_THROW(at(a, 4), fail_fast);
}
+
+ TEST(InitializerList)
+ {
+ std::initializer_list<int> a = { 1, 2, 3, 4 };
+
+ for (int i = 0; i < 4; ++i)
+ CHECK(at(a, i) == i+1);
+
+ CHECK_THROW(at(a, 4), fail_fast);
+ }
}
int main(int, const char *[])