initializer_list 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // -*- C++ -*-
  2. //===----------------------- initializer_list -----------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_INITIALIZER_LIST
  11. #define _LIBCPP_INITIALIZER_LIST
  12. /*
  13. initializer_list synopsis
  14. namespace std
  15. {
  16. template<class E>
  17. class initializer_list
  18. {
  19. public:
  20. typedef E value_type;
  21. typedef const E& reference;
  22. typedef const E& const_reference;
  23. typedef size_t size_type;
  24. typedef const E* iterator;
  25. typedef const E* const_iterator;
  26. initializer_list() noexcept; // constexpr in C++14
  27. size_t size() const noexcept; // constexpr in C++14
  28. const E* begin() const noexcept; // constexpr in C++14
  29. const E* end() const noexcept; // constexpr in C++14
  30. };
  31. template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14
  32. template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
  33. } // std
  34. */
  35. #include <__config>
  36. #include <cstddef>
  37. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  38. #pragma GCC system_header
  39. #endif
  40. namespace std // purposefully not versioned
  41. {
  42. #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  43. template<class _Ep>
  44. class _LIBCPP_TYPE_VIS_ONLY initializer_list
  45. {
  46. const _Ep* __begin_;
  47. size_t __size_;
  48. _LIBCPP_ALWAYS_INLINE
  49. _LIBCPP_CONSTEXPR_AFTER_CXX11
  50. initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
  51. : __begin_(__b),
  52. __size_(__s)
  53. {}
  54. public:
  55. typedef _Ep value_type;
  56. typedef const _Ep& reference;
  57. typedef const _Ep& const_reference;
  58. typedef size_t size_type;
  59. typedef const _Ep* iterator;
  60. typedef const _Ep* const_iterator;
  61. _LIBCPP_ALWAYS_INLINE
  62. _LIBCPP_CONSTEXPR_AFTER_CXX11
  63. initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
  64. _LIBCPP_ALWAYS_INLINE
  65. _LIBCPP_CONSTEXPR_AFTER_CXX11
  66. size_t size() const _NOEXCEPT {return __size_;}
  67. _LIBCPP_ALWAYS_INLINE
  68. _LIBCPP_CONSTEXPR_AFTER_CXX11
  69. const _Ep* begin() const _NOEXCEPT {return __begin_;}
  70. _LIBCPP_ALWAYS_INLINE
  71. _LIBCPP_CONSTEXPR_AFTER_CXX11
  72. const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
  73. };
  74. template<class _Ep>
  75. inline _LIBCPP_INLINE_VISIBILITY
  76. _LIBCPP_CONSTEXPR_AFTER_CXX11
  77. const _Ep*
  78. begin(initializer_list<_Ep> __il) _NOEXCEPT
  79. {
  80. return __il.begin();
  81. }
  82. template<class _Ep>
  83. inline _LIBCPP_INLINE_VISIBILITY
  84. _LIBCPP_CONSTEXPR_AFTER_CXX11
  85. const _Ep*
  86. end(initializer_list<_Ep> __il) _NOEXCEPT
  87. {
  88. return __il.end();
  89. }
  90. #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
  91. } // std
  92. #endif // _LIBCPP_INITIALIZER_LIST