1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03 11 12 // template<class E> class initializer_list; 13 14 // const E* begin() const; 15 // const E* end() const; 16 // size_t size() const; 17 18 #include <initializer_list> 19 #include <cassert> 20 #include <cstddef> 21 22 #include "test_macros.h" 23 24 struct A 25 { AA26 A(std::initializer_list<int> il) 27 { 28 const int* b = il.begin(); 29 const int* e = il.end(); 30 assert(il.size() == 3); 31 assert(static_cast<std::size_t>(e - b) == il.size()); 32 assert(*b++ == 3); 33 assert(*b++ == 2); 34 assert(*b++ == 1); 35 } 36 }; 37 38 #if TEST_STD_VER > 11 39 struct B 40 { BB41 constexpr B(std::initializer_list<int> il) 42 { 43 const int* b = il.begin(); 44 const int* e = il.end(); 45 assert(il.size() == 3); 46 assert(static_cast<std::size_t>(e - b) == il.size()); 47 assert(*b++ == 3); 48 assert(*b++ == 2); 49 assert(*b++ == 1); 50 } 51 }; 52 53 #endif // TEST_STD_VER > 11 54 main()55int main() 56 { 57 A test1 = {3, 2, 1}; 58 #if TEST_STD_VER > 11 59 constexpr B test2 = {3, 2, 1}; 60 (void)test2; 61 #endif // TEST_STD_VER > 11 62 } 63