diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 | 
| commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
| tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/containers/sequences/array | |
| parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) | |
Notes
Diffstat (limited to 'test/std/containers/sequences/array')
23 files changed, 1012 insertions, 0 deletions
diff --git a/test/std/containers/sequences/array/array.cons/default.pass.cpp b/test/std/containers/sequences/array/array.cons/default.pass.cpp new file mode 100644 index 000000000000..7bc62b759c35 --- /dev/null +++ b/test/std/containers/sequences/array/array.cons/default.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// array(); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c; +        assert(c.size() == 3); +    } +    { +        typedef double T; +        typedef std::array<T, 0> C; +        C c; +        assert(c.size() == 0); +    } +} 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 new file mode 100644 index 000000000000..b9775eef0673 --- /dev/null +++ b/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// Construct with initizializer list + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        assert(c.size() == 3); +        assert(c[0] == 1); +        assert(c[1] == 2); +        assert(c[2] == 3.5); +    } +    { +        typedef double T; +        typedef std::array<T, 0> C; +        C c = {}; +        assert(c.size() == 0); +    } +} diff --git a/test/std/containers/sequences/array/array.data/data.pass.cpp b/test/std/containers/sequences/array/array.data/data.pass.cpp new file mode 100644 index 000000000000..08e4fd39d377 --- /dev/null +++ b/test/std/containers/sequences/array/array.data/data.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// T *data(); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        T* p = c.data(); +        assert(p[0] == 1); +        assert(p[1] == 2); +        assert(p[2] == 3.5); +    } +    { +        typedef double T; +        typedef std::array<T, 0> C; +        C c = {}; +        T* p = c.data(); +        (void)p; // to placate scan-build +    } +} diff --git a/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/test/std/containers/sequences/array/array.data/data_const.pass.cpp new file mode 100644 index 000000000000..8eb9762dcb89 --- /dev/null +++ b/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// const T* data() const; + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        const C c = {1, 2, 3.5}; +        const T* p = c.data(); +        assert(p[0] == 1); +        assert(p[1] == 2); +        assert(p[2] == 3.5); +    } +    { +        typedef double T; +        typedef std::array<T, 0> C; +        const C c = {}; +        const T* p = c.data(); +        (void)p; // to placate scan-build +    } +} diff --git a/test/std/containers/sequences/array/array.fill/fill.pass.cpp b/test/std/containers/sequences/array/array.fill/fill.pass.cpp new file mode 100644 index 000000000000..675f49500627 --- /dev/null +++ b/test/std/containers/sequences/array/array.fill/fill.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// void fill(const T& u); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        c.fill(5.5); +        assert(c.size() == 3); +        assert(c[0] == 5.5); +        assert(c[1] == 5.5); +        assert(c[2] == 5.5); +    } +    { +        typedef double T; +        typedef std::array<T, 0> C; +        C c = {}; +        c.fill(5.5); +        assert(c.size() == 0); +    } +} diff --git a/test/std/containers/sequences/array/array.size/size.pass.cpp b/test/std/containers/sequences/array/array.size/size.pass.cpp new file mode 100644 index 000000000000..fe5a0d5c8db0 --- /dev/null +++ b/test/std/containers/sequences/array/array.size/size.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// template <class T, size_t N> constexpr size_type array<T,N>::size(); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        assert(c.size() == 3); +        assert(c.max_size() == 3); +        assert(!c.empty()); +    } +    { +        typedef double T; +        typedef std::array<T, 0> C; +        C c = {}; +        assert(c.size() == 0); +        assert(c.max_size() == 0); +        assert(c.empty()); +    } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR +    { +        typedef double T; +        typedef std::array<T, 3> C; +        constexpr C c = {1, 2, 3.5}; +        static_assert(c.size() == 3, ""); +        static_assert(c.max_size() == 3, ""); +        static_assert(!c.empty(), ""); +    } +    { +        typedef double T; +        typedef std::array<T, 0> C; +        constexpr C c = {}; +        static_assert(c.size() == 0, ""); +        static_assert(c.max_size() == 0, ""); +        static_assert(c.empty(), ""); +    } +#endif +} diff --git a/test/std/containers/sequences/array/array.special/swap.pass.cpp b/test/std/containers/sequences/array/array.special/swap.pass.cpp new file mode 100644 index 000000000000..08e437739ee6 --- /dev/null +++ b/test/std/containers/sequences/array/array.special/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// template <class T, size_t N> void swap(array<T,N>& x, array<T,N>& y); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c1 = {1, 2, 3.5}; +        C c2 = {4, 5, 6.5}; +        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 = {}; +        swap(c1, c2); +        assert(c1.size() == 0); +        assert(c2.size() == 0); +    } +} diff --git a/test/std/containers/sequences/array/array.swap/swap.pass.cpp b/test/std/containers/sequences/array/array.swap/swap.pass.cpp new file mode 100644 index 000000000000..c7a4cb8df38c --- /dev/null +++ b/test/std/containers/sequences/array/array.swap/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// void swap(array& a); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c1 = {1, 2, 3.5}; +        C c2 = {4, 5, 6.5}; +        c1.swap(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 = {}; +        c1.swap(c2); +        assert(c1.size() == 0); +        assert(c2.size() == 0); +    } +} diff --git a/test/std/containers/sequences/array/array.tuple/get.fail.cpp b/test/std/containers/sequences/array/array.tuple/get.fail.cpp new file mode 100644 index 000000000000..4f4fbcf93af6 --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/get.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// template <size_t I, class T, size_t N> T& get(array<T, N>& a); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        std::get<3>(c) = 5.5;    // Can't get element 3! +    } +} diff --git a/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/test/std/containers/sequences/array/array.tuple/get.pass.cpp new file mode 100644 index 000000000000..d9e242cd420b --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/get.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// template <size_t I, class T, size_t N> T& get(array<T, N>& a); + +#include <array> +#include <cassert> + +#if __cplusplus > 201103L +struct S { +   std::array<int, 3> a; +   int k; +   constexpr S() : a{1,2,3}, k(std::get<2>(a)) {} +   }; + +constexpr std::array<int, 2> getArr () { return { 3, 4 }; } +#endif + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        std::get<1>(c) = 5.5; +        assert(c[0] == 1); +        assert(c[1] == 5.5); +        assert(c[2] == 3.5); +    } +#if _LIBCPP_STD_VER > 11 +    { +        typedef double T; +        typedef std::array<T, 3> C; +        constexpr C c = {1, 2, 3.5}; +        static_assert(std::get<0>(c) == 1, ""); +        static_assert(std::get<1>(c) == 2, ""); +        static_assert(std::get<2>(c) == 3.5, ""); +    } +    { +        static_assert(S().k == 3, ""); +        static_assert(std::get<1>(getArr()) == 4, ""); +    } +#endif +} diff --git a/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp new file mode 100644 index 000000000000..1cbdfa4ff393 --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// template <size_t I, class T, size_t N> const T& get(const array<T, N>& a); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        const C c = {1, 2, 3.5}; +        assert(std::get<0>(c) == 1); +        assert(std::get<1>(c) == 2); +        assert(std::get<2>(c) == 3.5); +    } +#if _LIBCPP_STD_VER > 11 +    { +        typedef double T; +        typedef std::array<T, 3> C; +        constexpr const C c = {1, 2, 3.5}; +        static_assert(std::get<0>(c) == 1, ""); +        static_assert(std::get<1>(c) == 2, ""); +        static_assert(std::get<2>(c) == 3.5, ""); +    } +#endif +} diff --git a/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp b/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp new file mode 100644 index 000000000000..8eec3ceff514 --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// template <size_t I, class T, size_t N> T&& get(array<T, N>&& a); + +#include <array> +#include <memory> +#include <utility> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +    { +        typedef std::unique_ptr<double> T; +        typedef std::array<T, 1> C; +        C c = {std::unique_ptr<double>(new double(3.5))}; +        T t = std::get<0>(std::move(c)); +        assert(*t == 3.5); +    } +#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp b/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp new file mode 100644 index 000000000000..91d6b4e5da22 --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// tuple_element<I, array<T, N> >::type + +#include <array> +#include <type_traits> + +template <class T> +void test() +{ +    { +    typedef T Exp; +    typedef std::array<T, 3> C; +    static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), ""); +    } +    { +    typedef T const Exp; +    typedef std::array<T, 3> const C; +    static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), ""); +    } +    { +    typedef T volatile Exp; +    typedef std::array<T, 3> volatile C; +    static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), ""); +    } +    { +    typedef T const volatile Exp; +    typedef std::array<T, 3> const volatile C; +    static_assert((std::is_same<typename std::tuple_element<0, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<1, C>::type, Exp>::value), ""); +    static_assert((std::is_same<typename std::tuple_element<2, C>::type, Exp>::value), ""); +    } +} + +int main() +{ +    test<double>(); +    test<int>(); +} diff --git a/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp b/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp new file mode 100644 index 000000000000..1e565d1946e4 --- /dev/null +++ b/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// tuple_size<array<T, N> >::value + +#include <array> + +template <class T, std::size_t N> +void test() +{ +    { +    typedef std::array<T, N> C; +    static_assert((std::tuple_size<C>::value == N), ""); +    } +    { +    typedef std::array<T const, N> C; +    static_assert((std::tuple_size<C>::value == N), ""); +    } +    { +    typedef std::array<T volatile, N> C; +    static_assert((std::tuple_size<C>::value == N), ""); +    } +    { +    typedef std::array<T const volatile, N> C; +    static_assert((std::tuple_size<C>::value == N), ""); +    } +} + +int main() +{ +    test<double, 0>(); +    test<double, 3>(); +    test<double, 5>(); +} diff --git a/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp b/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp new file mode 100644 index 000000000000..0aa2f50d8b4f --- /dev/null +++ b/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// support for zero-sized array + +#include <array> + +int main() +{ +} diff --git a/test/std/containers/sequences/array/at.pass.cpp b/test/std/containers/sequences/array/at.pass.cpp new file mode 100644 index 000000000000..b5cf8a5aaa8f --- /dev/null +++ b/test/std/containers/sequences/array/at.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// reference operator[] (size_type) +// const_reference operator[] (size_type); // constexpr in C++14 +// reference at (size_type) +// const_reference at (size_type); // constexpr in C++14 + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        C::reference r1 = c.at(0); +        assert(r1 == 1); +        r1 = 5.5; +        assert(c.front() == 5.5); +         +        C::reference r2 = c.at(2); +        assert(r2 == 3.5); +        r2 = 7.5; +        assert(c.back() == 7.5); + +        try { (void) c.at(3); } +        catch (const std::out_of_range &) {} +    } +    { +        typedef double T; +        typedef std::array<T, 3> C; +        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 _LIBCPP_STD_VER > 11  +    { +        typedef double T; +        typedef std::array<T, 3> C; +        constexpr C c = {1, 2, 3.5}; + +        constexpr T t1 = c.at(0); +        static_assert (t1 == 1, ""); + +        constexpr T t2 = c.at(2); +        static_assert (t2 == 3.5, ""); +    } +#endif + +} diff --git a/test/std/containers/sequences/array/begin.pass.cpp b/test/std/containers/sequences/array/begin.pass.cpp new file mode 100644 index 000000000000..9cba0d6fceb0 --- /dev/null +++ b/test/std/containers/sequences/array/begin.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// iterator begin(); + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        C::iterator i; +        i = c.begin(); +        assert(*i == 1); +        assert(&*i == c.data()); +        *i = 5.5; +        assert(c[0] == 5.5); +    } +    { +    } +} diff --git a/test/std/containers/sequences/array/contiguous.pass.cpp b/test/std/containers/sequences/array/contiguous.pass.cpp new file mode 100644 index 000000000000..27933b0c5df8 --- /dev/null +++ b/test/std/containers/sequences/array/contiguous.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// An array is a contiguous container + +#include <array> +#include <cassert> + +template <class C> +void test_contiguous ( const C &c ) +{ +    for ( size_t i = 0; i < c.size(); ++i ) +        assert ( *(c.begin() + i) == *(std::addressof(*c.begin()) + i)); +} + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        test_contiguous (C()); +    } +} diff --git a/test/std/containers/sequences/array/front_back.pass.cpp b/test/std/containers/sequences/array/front_back.pass.cpp new file mode 100644 index 000000000000..45a963b9947d --- /dev/null +++ b/test/std/containers/sequences/array/front_back.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// reference front(); +// reference back(); +// const_reference front(); // constexpr in C++14 +// const_reference back(); // constexpr in C++14 + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; + +        C::reference r1 = c.front(); +        assert(r1 == 1); +        r1 = 5.5; +        assert(c[0] == 5.5); +         +        C::reference r2 = c.back(); +        assert(r2 == 3.5); +        r2 = 7.5; +        assert(c[2] == 7.5); +    } +    { +        typedef double T; +        typedef std::array<T, 3> C; +        const C c = {1, 2, 3.5}; +        C::const_reference r1 = c.front(); +        assert(r1 == 1); + +        C::const_reference r2 = c.back(); +        assert(r2 == 3.5); +    } + +#if _LIBCPP_STD_VER > 11  +    { +        typedef double T; +        typedef std::array<T, 3> C; +        constexpr C c = {1, 2, 3.5}; +         +        constexpr T t1 = c.front(); +        static_assert (t1 == 1, ""); + +        constexpr T t2 = c.back(); +        static_assert (t2 == 3.5, ""); +    } +#endif + +} diff --git a/test/std/containers/sequences/array/indexing.pass.cpp b/test/std/containers/sequences/array/indexing.pass.cpp new file mode 100644 index 000000000000..e4dda0dc5cfd --- /dev/null +++ b/test/std/containers/sequences/array/indexing.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// reference operator[] (size_type) +// const_reference operator[] (size_type); // constexpr in C++14 +// reference at (size_type) +// const_reference at (size_type); // constexpr in C++14 + +#include <array> +#include <cassert> + +int main() +{ +    { +        typedef double T; +        typedef std::array<T, 3> C; +        C c = {1, 2, 3.5}; +        C::reference r1 = c[0]; +        assert(r1 == 1); +        r1 = 5.5; +        assert(c.front() == 5.5); +         +        C::reference r2 = c[2]; +        assert(r2 == 3.5); +        r2 = 7.5; +        assert(c.back() == 7.5); +    } +    { +        typedef double T; +        typedef std::array<T, 3> C; +        const C c = {1, 2, 3.5}; +        C::const_reference r1 = c[0]; +        assert(r1 == 1); +        C::const_reference r2 = c[2]; +        assert(r2 == 3.5); +    } +     +#if _LIBCPP_STD_VER > 11  +    { +        typedef double T; +        typedef std::array<T, 3> C; +        constexpr C c = {1, 2, 3.5}; +         +        constexpr T t1 = c[0]; +        static_assert (t1 == 1, ""); + +        constexpr T t2 = c[2]; +        static_assert (t2 == 3.5, ""); +    } +#endif + +} diff --git a/test/std/containers/sequences/array/iterators.pass.cpp b/test/std/containers/sequences/array/iterators.pass.cpp new file mode 100644 index 000000000000..98997d8c26d5 --- /dev/null +++ b/test/std/containers/sequences/array/iterators.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// iterator, const_iterator + +#include <array> +#include <iterator> +#include <cassert> + +int main() +{ +    { +    typedef std::array<int, 5> C; +    C c; +    C::iterator i; +    i = c.begin(); +    C::const_iterator j; +    j = c.cbegin(); +    assert(i == j); +    } +    { +    typedef std::array<int, 0> C; +    C c; +    C::iterator i; +    i = c.begin(); +    C::const_iterator j; +    j = c.cbegin(); +    assert(i == j); +    } + +#if _LIBCPP_STD_VER > 11 +    { // N3644 testing +        { +        typedef std::array<int, 5> C; +        C::iterator ii1{}, ii2{}; +        C::iterator ii4 = ii1; +        C::const_iterator cii{}; +        assert ( ii1 == ii2 ); +        assert ( ii1 == ii4 ); +        assert ( ii1 == cii ); + +        assert ( !(ii1 != ii2 )); +        assert ( !(ii1 != cii )); + +        C c; +        assert ( c.begin()   == std::begin(c)); +        assert ( c.cbegin()  == std::cbegin(c)); +        assert ( c.rbegin()  == std::rbegin(c)); +        assert ( c.crbegin() == std::crbegin(c)); +        assert ( c.end()     == std::end(c)); +        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)); +        assert ( std::crbegin(c) != std::crend(c)); +        } +        { +        typedef std::array<int, 0> C; +        C::iterator ii1{}, ii2{}; +        C::iterator ii4 = ii1; +        C::const_iterator cii{}; +        assert ( ii1 == ii2 ); +        assert ( ii1 == ii4 ); + +        assert (!(ii1 != ii2 )); + +        assert ( (ii1 == cii )); +        assert ( (cii == ii1 )); +        assert (!(ii1 != cii )); +        assert (!(cii != ii1 )); +        assert (!(ii1 <  cii )); +        assert (!(cii <  ii1 )); +        assert ( (ii1 <= cii )); +        assert ( (cii <= ii1 )); +        assert (!(ii1 >  cii )); +        assert (!(cii >  ii1 )); +        assert ( (ii1 >= cii )); +        assert ( (cii >= ii1 )); +        assert (cii - ii1 == 0); +        assert (ii1 - cii == 0); + +        C c; +        assert ( c.begin()   == std::begin(c)); +        assert ( c.cbegin()  == std::cbegin(c)); +        assert ( c.rbegin()  == std::rbegin(c)); +        assert ( c.crbegin() == std::crbegin(c)); +        assert ( c.end()     == std::end(c)); +        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)); +        assert ( std::crbegin(c) == std::crend(c)); +        } +    } +#endif +} diff --git a/test/std/containers/sequences/array/types.pass.cpp b/test/std/containers/sequences/array/types.pass.cpp new file mode 100644 index 000000000000..065ade959d05 --- /dev/null +++ b/test/std/containers/sequences/array/types.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +//                     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> + +// template <class T, size_t N > +// struct array +// { +//     // types: +//     typedef T& reference; +//     typedef const T& const_reference; +//     typedef implementation defined iterator; +//     typedef implementation defined const_iterator; +//     typedef T value_type; +//     typedef T* pointer; +//     typedef size_t size_type; +//     typedef ptrdiff_t difference_type; +//     typedef T value_type; +//     typedef std::reverse_iterator<iterator> reverse_iterator; +//     typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + +#include <array> +#include <iterator> +#include <type_traits> + +int main() +{ +    { +        typedef double T; +        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), ""); +        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), ""); +    } +    { +        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), ""); +        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), ""); +    } +} diff --git a/test/std/containers/sequences/array/version.pass.cpp b/test/std/containers/sequences/array/version.pass.cpp new file mode 100644 index 000000000000..b89a8dd8cca3 --- /dev/null +++ b/test/std/containers/sequences/array/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +//                     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() +{ +}  | 
