diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-01-04 17:58:17 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-01-04 17:58:17 +0000 |
commit | 020b623a3b03a89aa56beba357bfa27c36cf13a7 (patch) | |
tree | 524e8201eb9d25861affd059a55f1123ec75d943 /libcxx/test/std | |
parent | df8a13b25763b7192579c74049322e5e6dd3da54 (diff) | |
download | bcm5719-llvm-020b623a3b03a89aa56beba357bfa27c36cf13a7.tar.gz bcm5719-llvm-020b623a3b03a89aa56beba357bfa27c36cf13a7.zip |
Implement the last bit of P0031: 'A Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range Access' for C++17
llvm-svn: 290976
Diffstat (limited to 'libcxx/test/std')
3 files changed, 109 insertions, 6 deletions
diff --git a/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp index 58840e94089..5be082eeb84 100644 --- a/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp +++ b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -14,6 +14,8 @@ #include <array> #include <cassert> +#include "test_macros.h" + // std::array is explicitly allowed to be initialized with A a = { init-list };. // Disable the missing braces warning for this reason. #include "disable_missing_braces_warning.h" @@ -36,4 +38,16 @@ int main() const T* p = c.data(); (void)p; // to placate scan-build } +#if TEST_STD_VER > 14 + { + typedef std::array<int, 5> C; + constexpr C c1{0,1,2,3,4}; + constexpr const C c2{0,1,2,3,4}; + + static_assert ( c1.data() == &c1[0], ""); + static_assert ( *c1.data() == c1[0], ""); + static_assert ( c2.data() == &c2[0], ""); + static_assert ( *c2.data() == c2[0], ""); + } +#endif } diff --git a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp index 1f9904e1fa7..7d9050800de 100644 --- a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp +++ b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp @@ -17,6 +17,10 @@ #include "test_macros.h" +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -109,4 +113,33 @@ int main() } } #endif +#if TEST_STD_VER > 14 + { + typedef std::array<int, 5> C; + constexpr C c{0,1,2,3,4}; + + static_assert ( c.begin() == std::begin(c), ""); + static_assert ( c.cbegin() == std::cbegin(c), ""); + static_assert ( c.end() == std::end(c), ""); + static_assert ( c.cend() == std::cend(c), ""); + + static_assert ( c.rbegin() == std::rbegin(c), ""); + static_assert ( c.crbegin() == std::crbegin(c), ""); + static_assert ( c.rend() == std::rend(c), ""); + static_assert ( c.crend() == std::crend(c), ""); + + static_assert ( std::begin(c) != std::end(c), ""); + static_assert ( std::rbegin(c) != std::rend(c), ""); + static_assert ( std::cbegin(c) != std::cend(c), ""); + static_assert ( std::crbegin(c) != std::crend(c), ""); + + static_assert ( *c.begin() == 0, ""); + static_assert ( *c.rbegin() == 4, ""); + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } +#endif } diff --git a/libcxx/test/std/iterators/iterator.range/begin-end.pass.cpp b/libcxx/test/std/iterators/iterator.range/begin-end.pass.cpp index 68186919198..a0774888d56 100644 --- a/libcxx/test/std/iterators/iterator.range/begin-end.pass.cpp +++ b/libcxx/test/std/iterators/iterator.range/begin-end.pass.cpp @@ -10,12 +10,25 @@ // XFAIL: c++03, c++98 // <iterator> -// template <class C> auto begin(C& c) -> decltype(c.begin()); -// template <class C> auto begin(const C& c) -> decltype(c.begin()); -// template <class C> auto end(C& c) -> decltype(c.end()); -// template <class C> auto end(const C& c) -> decltype(c.end()); -// template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il); -// template <class E> reverse_iterator<const E*> rend(initializer_list<E> il); +// template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); +// template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); +// template <class C> constexpr auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14 +// template <class C> constexpr auto cend(const C& c) -> decltype(std::end(c)); // C++14 +// template <class C> constexpr auto end (C& c) -> decltype(c.end()); +// template <class C> constexpr auto end (const C& c) -> decltype(c.end()); +// template <class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il); +// template <class E> constexpr reverse_iterator<const E*> rend (initializer_list<E> il); +// +// template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 +// template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 +// template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 +// template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 +// template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 +// template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 +// template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 +// template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 +// +// All of these are constexpr in C++17 #include "test_macros.h" @@ -26,6 +39,10 @@ #include <list> #include <initializer_list> +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + template<typename C> void test_const_container( const C & c, typename C::value_type val ) { assert ( std::begin(c) == c.begin()); @@ -142,4 +159,43 @@ int main(){ constexpr const int *e = std::cend(arrA); static_assert(e - b == 3, ""); #endif + +#if TEST_STD_VER > 14 + { + typedef std::array<int, 5> C; + constexpr const C c{0,1,2,3,4}; + + static_assert ( c.begin() == std::begin(c), ""); + static_assert ( c.cbegin() == std::cbegin(c), ""); + static_assert ( c.end() == std::end(c), ""); + static_assert ( c.cend() == std::cend(c), ""); + + static_assert ( c.rbegin() == std::rbegin(c), ""); + static_assert ( c.crbegin() == std::crbegin(c), ""); + static_assert ( c.rend() == std::rend(c), ""); + static_assert ( c.crend() == std::crend(c), ""); + + static_assert ( std::begin(c) != std::end(c), ""); + static_assert ( std::rbegin(c) != std::rend(c), ""); + static_assert ( std::cbegin(c) != std::cend(c), ""); + static_assert ( std::crbegin(c) != std::crend(c), ""); + + static_assert ( *c.begin() == 0, ""); + static_assert ( *c.rbegin() == 4, ""); + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } + + { + static constexpr const int c[] = {0,1,2,3,4}; + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } +#endif } |