1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // Make sure std::array is an aggregate type. 10 11 #include <array> 12 #include <type_traits> 13 14 template <typename T> 15 void tests() 16 { 17 // Test aggregate initialization 18 { 19 std::array<T, 0> a0 = {}; (void)a0; 20 std::array<T, 1> a1 = {T()}; (void)a1; 21 std::array<T, 2> a2 = {T(), T()}; (void)a2; 22 std::array<T, 3> a3 = {T(), T(), T()}; (void)a3; 23 } 24 25 // Test the is_aggregate trait. 26 #if TEST_STD_VER >= 17 // The trait is only available in C++17 and above 27 static_assert(std::is_aggregate<std::array<T, 0> >::value, ""); 28 static_assert(std::is_aggregate<std::array<T, 1> >::value, ""); 29 static_assert(std::is_aggregate<std::array<T, 2> >::value, ""); 30 static_assert(std::is_aggregate<std::array<T, 3> >::value, ""); 31 static_assert(std::is_aggregate<std::array<T, 4> >::value, ""); 32 #endif 33 } 34 35 struct Empty { }; 36 struct NonEmpty { int i; int j; }; 37 38 int main(int, char**) 39 { 40 tests<char>(); 41 tests<int>(); 42 tests<long>(); 43 tests<float>(); 44 tests<double>(); 45 tests<long double>(); 46 tests<NonEmpty>(); 47 tests<Empty>(); 48 49 return 0; 50 } 51