diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2013-07-17 18:25:36 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2013-07-17 18:25:36 +0000 |
commit | 8bf1f08a2cea3d28e173555c11bfab59dd16b231 (patch) | |
tree | 37c1f9b79dd01398a31d9b0d0b477ebc8581c41f /libcxx/test/containers/sequences | |
parent | 39655749295f739a5dc51cbe5a5e541485ba2a5b (diff) | |
download | bcm5719-llvm-8bf1f08a2cea3d28e173555c11bfab59dd16b231.tar.gz bcm5719-llvm-8bf1f08a2cea3d28e173555c11bfab59dd16b231.zip |
Make std::get constexpr
llvm-svn: 186525
Diffstat (limited to 'libcxx/test/containers/sequences')
6 files changed, 231 insertions, 0 deletions
diff --git a/libcxx/test/containers/sequences/array/array.size/size.pass.cpp b/libcxx/test/containers/sequences/array/array.size/size.pass.cpp index 4078fd5ca9f..fe5a0d5c8db 100644 --- a/libcxx/test/containers/sequences/array/array.size/size.pass.cpp +++ b/libcxx/test/containers/sequences/array/array.size/size.pass.cpp @@ -21,12 +21,16 @@ int main() 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 { @@ -34,12 +38,16 @@ int main() 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/libcxx/test/containers/sequences/array/array.tuple/get.pass.cpp b/libcxx/test/containers/sequences/array/array.tuple/get.pass.cpp index 9820babcd24..d9e242cd420 100644 --- a/libcxx/test/containers/sequences/array/array.tuple/get.pass.cpp +++ b/libcxx/test/containers/sequences/array/array.tuple/get.pass.cpp @@ -14,6 +14,16 @@ #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() { { @@ -25,4 +35,18 @@ int main() 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/libcxx/test/containers/sequences/array/array.tuple/get_const.pass.cpp b/libcxx/test/containers/sequences/array/array.tuple/get_const.pass.cpp index 6ede8f0c784..1cbdfa4ff39 100644 --- a/libcxx/test/containers/sequences/array/array.tuple/get_const.pass.cpp +++ b/libcxx/test/containers/sequences/array/array.tuple/get_const.pass.cpp @@ -24,4 +24,14 @@ int main() 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/libcxx/test/containers/sequences/array/at.pass.cpp b/libcxx/test/containers/sequences/array/at.pass.cpp new file mode 100644 index 00000000000..b5cf8a5aaa8 --- /dev/null +++ b/libcxx/test/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/libcxx/test/containers/sequences/array/front_back.pass.cpp b/libcxx/test/containers/sequences/array/front_back.pass.cpp new file mode 100644 index 00000000000..45a963b9947 --- /dev/null +++ b/libcxx/test/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/libcxx/test/containers/sequences/array/indexing.pass.cpp b/libcxx/test/containers/sequences/array/indexing.pass.cpp new file mode 100644 index 00000000000..e4dda0dc5cf --- /dev/null +++ b/libcxx/test/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 + +} |