diff options
Diffstat (limited to 'test/std/containers/sequences/array')
9 files changed, 143 insertions, 30 deletions
diff --git a/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp b/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp index 5e429adb6fc9..64ea75a40064 100644 --- a/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp +++ b/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp @@ -35,4 +35,18 @@ int main() C c = {}; assert(c.size() == 0); } + + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1}; + assert(c.size() == 3.0); + assert(c[0] == 1); + } + { + typedef int T; + typedef std::array<T, 1> C; + C c = {}; + assert(c.size() == 1); + } } diff --git a/test/std/containers/sequences/array/array.special/swap.pass.cpp b/test/std/containers/sequences/array/array.special/swap.pass.cpp index c1b0b235ab34..413f291a2a36 100644 --- a/test/std/containers/sequences/array/array.special/swap.pass.cpp +++ b/test/std/containers/sequences/array/array.special/swap.pass.cpp @@ -14,10 +14,28 @@ #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" +struct NonSwappable { + NonSwappable() {} +private: + NonSwappable(NonSwappable const&); + NonSwappable& operator=(NonSwappable const&); +}; + +template <class Tp> +decltype(swap(std::declval<Tp>(), std::declval<Tp>())) +can_swap_imp(int); + +template <class Tp> +std::false_type can_swap_imp(...); + +template <class Tp> +struct can_swap : std::is_same<decltype(can_swap_imp<Tp>(0)), void> {}; + int main() { { @@ -44,4 +62,24 @@ int main() assert(c1.size() == 0); assert(c2.size() == 0); } + { + typedef NonSwappable T; + typedef std::array<T, 0> C0; + static_assert(can_swap<C0&>::value, ""); + C0 l = {}; + C0 r = {}; + swap(l, r); +#if TEST_STD_VER >= 11 + static_assert(noexcept(swap(l, r)), ""); +#endif + } +#if TEST_STD_VER >= 11 + { + // NonSwappable is still considered swappable in C++03 because there + // is no access control SFINAE. + typedef NonSwappable T; + typedef std::array<T, 42> C1; + static_assert(!can_swap<C1&>::value, ""); + } +#endif } diff --git a/test/std/containers/sequences/array/array.swap/swap.pass.cpp b/test/std/containers/sequences/array/array.swap/swap.pass.cpp index 651798e1e790..8d01dbf959ce 100644 --- a/test/std/containers/sequences/array/array.swap/swap.pass.cpp +++ b/test/std/containers/sequences/array/array.swap/swap.pass.cpp @@ -10,14 +10,24 @@ // <array> // void swap(array& a); +// namespace std { void swap(array<T, N> &x, array<T, N> &y); -#include <array> #include <cassert> +#include <array> + +#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" +struct NonSwappable { + NonSwappable() {} +private: + NonSwappable(NonSwappable const&); + NonSwappable& operator=(NonSwappable const&); +}; + int main() { { @@ -37,6 +47,22 @@ int main() } { typedef double T; + typedef std::array<T, 3> C; + C c1 = {1, 2, 3.5}; + C c2 = {4, 5, 6.5}; + std::swap(c1, c2); + assert(c1.size() == 3); + assert(c1[0] == 4); + assert(c1[1] == 5); + assert(c1[2] == 6.5); + assert(c2.size() == 3); + assert(c2[0] == 1); + assert(c2[1] == 2); + assert(c2[2] == 3.5); + } + + { + typedef double T; typedef std::array<T, 0> C; C c1 = {}; C c2 = {}; @@ -44,4 +70,24 @@ int main() assert(c1.size() == 0); assert(c2.size() == 0); } + { + typedef double T; + typedef std::array<T, 0> C; + C c1 = {}; + C c2 = {}; + std::swap(c1, c2); + assert(c1.size() == 0); + assert(c2.size() == 0); + } + { + typedef NonSwappable T; + typedef std::array<T, 0> C0; + C0 l = {}; + C0 r = {}; + l.swap(r); +#if TEST_STD_VER >= 11 + static_assert(noexcept(l.swap(r)), ""); +#endif + } + } diff --git a/test/std/containers/sequences/array/at.pass.cpp b/test/std/containers/sequences/array/at.pass.cpp index 5cb89dfeeb9a..9707beeb3946 100644 --- a/test/std/containers/sequences/array/at.pass.cpp +++ b/test/std/containers/sequences/array/at.pass.cpp @@ -49,14 +49,14 @@ int main() const C c = {1, 2, 3.5}; C::const_reference r1 = c.at(0); assert(r1 == 1); - + C::const_reference r2 = c.at(2); assert(r2 == 3.5); try { (void) c.at(3); } catch (const std::out_of_range &) {} } - + #if TEST_STD_VER > 11 { typedef double T; diff --git a/test/std/containers/sequences/array/front_back.pass.cpp b/test/std/containers/sequences/array/front_back.pass.cpp index bccaade986ea..7d53b8265e96 100644 --- a/test/std/containers/sequences/array/front_back.pass.cpp +++ b/test/std/containers/sequences/array/front_back.pass.cpp @@ -34,7 +34,7 @@ int main() assert(r1 == 1); r1 = 5.5; assert(c[0] == 5.5); - + C::reference r2 = c.back(); assert(r2 == 3.5); r2 = 7.5; diff --git a/test/std/containers/sequences/array/indexing.pass.cpp b/test/std/containers/sequences/array/indexing.pass.cpp index 5ccb0b487b95..64d2716a7592 100644 --- a/test/std/containers/sequences/array/indexing.pass.cpp +++ b/test/std/containers/sequences/array/indexing.pass.cpp @@ -33,7 +33,7 @@ int main() assert(r1 == 1); r1 = 5.5; assert(c.front() == 5.5); - + C::reference r2 = c[2]; assert(r2 == 3.5); r2 = 7.5; diff --git a/test/std/containers/sequences/array/iterators.pass.cpp b/test/std/containers/sequences/array/iterators.pass.cpp index 98997d8c26d5..233e9328c4ed 100644 --- a/test/std/containers/sequences/array/iterators.pass.cpp +++ b/test/std/containers/sequences/array/iterators.pass.cpp @@ -59,7 +59,7 @@ int main() assert ( c.cend() == std::cend(c)); assert ( c.rend() == std::rend(c)); assert ( c.crend() == std::crend(c)); - + assert ( std::begin(c) != std::end(c)); assert ( std::rbegin(c) != std::rend(c)); assert ( std::cbegin(c) != std::cend(c)); diff --git a/test/std/containers/sequences/array/types.pass.cpp b/test/std/containers/sequences/array/types.pass.cpp index 065ade959d05..9cf390c4eacb 100644 --- a/test/std/containers/sequences/array/types.pass.cpp +++ b/test/std/containers/sequences/array/types.pass.cpp @@ -29,6 +29,25 @@ #include <iterator> #include <type_traits> +#include "test_macros.h" + +template <class C> +void test_iterators() { + typedef std::iterator_traits<typename C::iterator> ItT; + typedef std::iterator_traits<typename C::const_iterator> CItT; + static_assert((std::is_same<typename ItT::iterator_category, std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same<typename ItT::value_type, typename C::value_type>::value), ""); + static_assert((std::is_same<typename ItT::reference, typename C::reference>::value), ""); + static_assert((std::is_same<typename ItT::pointer, typename C::pointer>::value), ""); + static_assert((std::is_same<typename ItT::difference_type, typename C::difference_type>::value), ""); + + static_assert((std::is_same<typename CItT::iterator_category, std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same<typename CItT::value_type, typename C::value_type>::value), ""); + static_assert((std::is_same<typename CItT::reference, typename C::const_reference>::value), ""); + static_assert((std::is_same<typename CItT::pointer, typename C::const_pointer>::value), ""); + static_assert((std::is_same<typename CItT::difference_type, typename C::difference_type>::value), ""); +} + int main() { { @@ -36,27 +55,43 @@ int main() typedef std::array<T, 10> C; static_assert((std::is_same<C::reference, T&>::value), ""); static_assert((std::is_same<C::const_reference, const T&>::value), ""); - static_assert((std::is_same<C::iterator, T*>::value), ""); - static_assert((std::is_same<C::const_iterator, const T*>::value), ""); + LIBCPP_STATIC_ASSERT((std::is_same<C::iterator, T*>::value), ""); + LIBCPP_STATIC_ASSERT((std::is_same<C::const_iterator, const T*>::value), ""); + test_iterators<C>(); static_assert((std::is_same<C::pointer, T*>::value), ""); static_assert((std::is_same<C::const_pointer, const T*>::value), ""); static_assert((std::is_same<C::size_type, std::size_t>::value), ""); static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), ""); static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), ""); + + static_assert((std::is_signed<typename C::difference_type>::value), ""); + static_assert((std::is_unsigned<typename C::size_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, + typename std::iterator_traits<typename C::iterator>::difference_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, + typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), ""); } { typedef int* T; typedef std::array<T, 0> C; static_assert((std::is_same<C::reference, T&>::value), ""); static_assert((std::is_same<C::const_reference, const T&>::value), ""); - static_assert((std::is_same<C::iterator, T*>::value), ""); - static_assert((std::is_same<C::const_iterator, const T*>::value), ""); + LIBCPP_STATIC_ASSERT((std::is_same<C::iterator, T*>::value), ""); + LIBCPP_STATIC_ASSERT((std::is_same<C::const_iterator, const T*>::value), ""); + test_iterators<C>(); static_assert((std::is_same<C::pointer, T*>::value), ""); static_assert((std::is_same<C::const_pointer, const T*>::value), ""); static_assert((std::is_same<C::size_type, std::size_t>::value), ""); static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), ""); static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), ""); + + static_assert((std::is_signed<typename C::difference_type>::value), ""); + static_assert((std::is_unsigned<typename C::size_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, + typename std::iterator_traits<typename C::iterator>::difference_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, + typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), ""); } } diff --git a/test/std/containers/sequences/array/version.pass.cpp b/test/std/containers/sequences/array/version.pass.cpp deleted file mode 100644 index b89a8dd8cca3..000000000000 --- a/test/std/containers/sequences/array/version.pass.cpp +++ /dev/null @@ -1,20 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <array> - -#include <array> - -#ifndef _LIBCPP_VERSION -#error _LIBCPP_VERSION not defined -#endif - -int main() -{ -} |
