diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2014-02-19 17:53:30 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2014-02-19 17:53:30 +0000 |
commit | 6c3f5ffbb8fea9f49d2aa2c3b7ee6e38bd877c98 (patch) | |
tree | 9d899673dd353c6b0f44ed93cb3fae3bda42eadb /libcxx/test/iterators | |
parent | 94008121fafecdf89f83a63249496e185bc9cd77 (diff) | |
download | bcm5719-llvm-6c3f5ffbb8fea9f49d2aa2c3b7ee6e38bd877c98.tar.gz bcm5719-llvm-6c3f5ffbb8fea9f49d2aa2c3b7ee6e38bd877c98.zip |
Implement LWG Issue: 2280. begin/end for arrays should be constexpr and noexcept, plus a drive-by fix for cbegin/cend suggested by Peter Sommerlad.
llvm-svn: 201703
Diffstat (limited to 'libcxx/test/iterators')
-rw-r--r-- | libcxx/test/iterators/iterator.range/begin-end.pass.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libcxx/test/iterators/iterator.range/begin-end.pass.cpp b/libcxx/test/iterators/iterator.range/begin-end.pass.cpp index 65d1a7bd910..abb6433e232 100644 --- a/libcxx/test/iterators/iterator.range/begin-end.pass.cpp +++ b/libcxx/test/iterators/iterator.range/begin-end.pass.cpp @@ -52,7 +52,7 @@ void test_const_container( const std::initializer_list<T> & c, T val ) { assert ( std::end(c) == c.end()); #if _LIBCPP_STD_VER > 11 // initializer_list doesn't have cbegin/cend/rbegin/rend -// but std::cbegin(),etc work (b/c they're general fn templates) +// but std::cbegin(),etc work (b/c they're general fn templates) // assert ( std::cbegin(c) == c.cbegin()); // assert ( std::cbegin(c) != c.cend()); // assert ( std::cend(c) == c.cend()); @@ -104,6 +104,20 @@ void test_container( std::initializer_list<T> & c, T val ) { #endif } +template<typename T, size_t Sz> +void test_const_array( const T (&array)[Sz] ) { + assert ( std::begin(array) == array ); + assert (*std::begin(array) == array[0] ); + assert ( std::begin(array) != std::end(array)); + assert ( std::end(array) == array + Sz); +#if _LIBCPP_STD_VER > 11 + assert ( std::cbegin(array) == array ); + assert (*std::cbegin(array) == array[0] ); + assert ( std::cbegin(array) != std::cend(array)); + assert ( std::cend(array) == array + Sz); +#endif + } + int main(){ std::vector<int> v; v.push_back(1); std::list<int> l; l.push_back(2); @@ -119,6 +133,14 @@ int main(){ test_const_container ( l, 2 ); test_const_container ( a, 3 ); test_const_container ( il, 4 ); + + static constexpr int arrA [] { 1, 2, 3 }; + test_const_array ( arrA ); +#if _LIBCPP_STD_VER > 11 + constexpr const int *b = std::cbegin(arrA); + constexpr const int *e = std::cend(arrA); + static_assert(e - b == 3, ""); +#endif } #else |