mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge branch 'master' into dev/neilmac/spec
This commit is contained in:
commit
cd80ef6146
@ -40,7 +40,7 @@ of your GSL source.
|
|||||||
|
|
||||||
These steps assume the source code of this repository has been cloned into a directory named `c:\GSL`.
|
These steps assume the source code of this repository has been cloned into a directory named `c:\GSL`.
|
||||||
|
|
||||||
1. Create a directory to contain the build outputs for a particular architecture (we name it c:\GSL\vs14-x86 in this example).
|
1. Create a directory to contain the build outputs for a particular architecture (we name it c:\GSL\build-x86 in this example).
|
||||||
|
|
||||||
cd GSL
|
cd GSL
|
||||||
md build-x86
|
md build-x86
|
||||||
|
@ -129,6 +129,10 @@ template <class Cont>
|
|||||||
constexpr typename Cont::value_type& at(Cont& cont, size_t index)
|
constexpr typename Cont::value_type& at(Cont& cont, size_t index)
|
||||||
{ Expects(index < cont.size()); return cont[index]; }
|
{ Expects(index < cont.size()); return cont[index]; }
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
constexpr const T& at(std::initializer_list<T> cont, size_t index)
|
||||||
|
{ Expects(index < cont.size()); return *(cont.begin() + index); }
|
||||||
|
|
||||||
} // namespace gsl
|
} // namespace gsl
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <UnitTest++/UnitTest++.h>
|
#include <UnitTest++/UnitTest++.h>
|
||||||
#include <gsl.h>
|
#include <gsl.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gsl;
|
using namespace gsl;
|
||||||
@ -52,6 +53,16 @@ SUITE(at_tests)
|
|||||||
|
|
||||||
CHECK_THROW(at(a, 4), fail_fast);
|
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 *[])
|
int main(int, const char *[])
|
||||||
|
Loading…
Reference in New Issue
Block a user