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 // UNSUPPORTED: c++03 10 11 // template<class E> class initializer_list; 12 13 // const E* begin() const; 14 // const E* end() const; 15 // size_t size() const; 16 17 #include <initializer_list> 18 #include <cassert> 19 #include <cstddef> 20 21 #include "test_macros.h" 22 23 struct A 24 { AA25 A(std::initializer_list<int> il) 26 { 27 const int* b = il.begin(); 28 const int* e = il.end(); 29 assert(il.size() == 3); 30 assert(static_cast<std::size_t>(e - b) == il.size()); 31 assert(*b++ == 3); 32 assert(*b++ == 2); 33 assert(*b++ == 1); 34 } 35 }; 36 37 #if TEST_STD_VER > 11 38 struct B 39 { BB40 constexpr B(std::initializer_list<int> il) 41 { 42 const int* b = il.begin(); 43 const int* e = il.end(); 44 assert(il.size() == 3); 45 assert(static_cast<std::size_t>(e - b) == il.size()); 46 assert(*b++ == 3); 47 assert(*b++ == 2); 48 assert(*b++ == 1); 49 } 50 }; 51 52 #endif // TEST_STD_VER > 11 53 main(int,char **)54int main(int, char**) 55 { 56 A test1 = {3, 2, 1}; (void)test1; 57 #if TEST_STD_VER > 11 58 constexpr B test2 = {3, 2, 1}; 59 (void)test2; 60 #endif // TEST_STD_VER > 11 61 62 return 0; 63 } 64