Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
35
test/std/containers/sequences/array/array.data/data.pass.cpp
Normal file
35
test/std/containers/sequences/array/array.data/data.pass.cpp
Normal file
@@ -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
|
||||
}
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
36
test/std/containers/sequences/array/array.fill/fill.pass.cpp
Normal file
36
test/std/containers/sequences/array/array.fill/fill.pass.cpp
Normal file
@@ -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);
|
||||
}
|
||||
}
|
53
test/std/containers/sequences/array/array.size/size.pass.cpp
Normal file
53
test/std/containers/sequences/array/array.size/size.pass.cpp
Normal file
@@ -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
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
43
test/std/containers/sequences/array/array.swap/swap.pass.cpp
Normal file
43
test/std/containers/sequences/array/array.swap/swap.pass.cpp
Normal file
@@ -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);
|
||||
}
|
||||
}
|
25
test/std/containers/sequences/array/array.tuple/get.fail.cpp
Normal file
25
test/std/containers/sequences/array/array.tuple/get.fail.cpp
Normal file
@@ -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!
|
||||
}
|
||||
}
|
52
test/std/containers/sequences/array/array.tuple/get.pass.cpp
Normal file
52
test/std/containers/sequences/array/array.tuple/get.pass.cpp
Normal file
@@ -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
|
||||
}
|
@@ -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
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 <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
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef double T;
|
||||
typedef std::array<T, 3> C;
|
||||
static_assert((std::is_same<std::tuple_element<0, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<1, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<2, C>::type, T>::value), "");
|
||||
}
|
||||
{
|
||||
typedef int T;
|
||||
typedef std::array<T, 3> C;
|
||||
static_assert((std::is_same<std::tuple_element<0, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<1, C>::type, T>::value), "");
|
||||
static_assert((std::is_same<std::tuple_element<2, C>::type, T>::value), "");
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef double T;
|
||||
typedef std::array<T, 3> C;
|
||||
static_assert((std::tuple_size<C>::value == 3), "");
|
||||
}
|
||||
{
|
||||
typedef double T;
|
||||
typedef std::array<T, 0> C;
|
||||
static_assert((std::tuple_size<C>::value == 0), "");
|
||||
}
|
||||
}
|
@@ -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()
|
||||
{
|
||||
}
|
67
test/std/containers/sequences/array/at.pass.cpp
Normal file
67
test/std/containers/sequences/array/at.pass.cpp
Normal file
@@ -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
|
||||
|
||||
}
|
32
test/std/containers/sequences/array/begin.pass.cpp
Normal file
32
test/std/containers/sequences/array/begin.pass.cpp
Normal file
@@ -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);
|
||||
}
|
||||
{
|
||||
}
|
||||
}
|
62
test/std/containers/sequences/array/front_back.pass.cpp
Normal file
62
test/std/containers/sequences/array/front_back.pass.cpp
Normal file
@@ -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
|
||||
|
||||
}
|
60
test/std/containers/sequences/array/indexing.pass.cpp
Normal file
60
test/std/containers/sequences/array/indexing.pass.cpp
Normal file
@@ -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
|
||||
|
||||
}
|
110
test/std/containers/sequences/array/iterators.pass.cpp
Normal file
110
test/std/containers/sequences/array/iterators.pass.cpp
Normal file
@@ -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
|
||||
}
|
62
test/std/containers/sequences/array/types.pass.cpp
Normal file
62
test/std/containers/sequences/array/types.pass.cpp
Normal file
@@ -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), "");
|
||||
}
|
||||
}
|
20
test/std/containers/sequences/array/version.pass.cpp
Normal file
20
test/std/containers/sequences/array/version.pass.cpp
Normal file
@@ -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()
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user