Home | History | Annotate | Download | only in support.initlist.access
      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 // template<class E> class initializer_list;
     11 
     12 // const E* begin() const;
     13 // const E* end() const;
     14 // size_t size() const;
     15 
     16 #include <initializer_list>
     17 #include <cassert>
     18 
     19 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     20 
     21 struct A
     22 {
     23     A(std::initializer_list<int> il)
     24     {
     25         const int* b = il.begin();
     26         const int* e = il.end();
     27         assert(il.size() == 3);
     28         assert(e - b == il.size());
     29         assert(*b++ == 3);
     30         assert(*b++ == 2);
     31         assert(*b++ == 1);
     32     }
     33 };
     34 
     35 #if _LIBCPP_STD_VER > 11
     36 struct B
     37 {
     38     constexpr B(std::initializer_list<int> il)
     39     {
     40         const int* b = il.begin();
     41         const int* e = il.end();
     42         assert(il.size() == 3);
     43         assert(e - b == il.size());
     44         assert(*b++ == 3);
     45         assert(*b++ == 2);
     46         assert(*b++ == 1);
     47     }
     48 };
     49 
     50 #endif  // _LIBCPP_STD_VER > 11
     51 
     52 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     53 
     54 int main()
     55 {
     56 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     57     A test1 = {3, 2, 1};
     58 #endif
     59 #if _LIBCPP_STD_VER > 11
     60     constexpr B test2 = {3, 2, 1};
     61 #endif  // _LIBCPP_STD_VER > 11
     62 }
     63