initializer_list 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_INITIALIZER_LIST
  10. #define _LIBCPP_INITIALIZER_LIST
  11. /*
  12. initializer_list synopsis
  13. namespace std
  14. {
  15. template<class E>
  16. class initializer_list
  17. {
  18. public:
  19. typedef E value_type;
  20. typedef const E& reference;
  21. typedef const E& const_reference;
  22. typedef size_t size_type;
  23. typedef const E* iterator;
  24. typedef const E* const_iterator;
  25. initializer_list() noexcept; // constexpr in C++14
  26. size_t size() const noexcept; // constexpr in C++14
  27. const E* begin() const noexcept; // constexpr in C++14
  28. const E* end() const noexcept; // constexpr in C++14
  29. };
  30. template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14
  31. template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
  32. } // std
  33. */
  34. #include <__config>
  35. #include <cstddef>
  36. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  37. # pragma GCC system_header
  38. #endif
  39. namespace std // purposefully not versioned
  40. {
  41. #ifndef _LIBCPP_CXX03_LANG
  42. template <class _Ep>
  43. class _LIBCPP_TEMPLATE_VIS initializer_list {
  44. const _Ep* __begin_;
  45. size_t __size_;
  46. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
  47. : __begin_(__b),
  48. __size_(__s) {}
  49. public:
  50. typedef _Ep value_type;
  51. typedef const _Ep& reference;
  52. typedef const _Ep& const_reference;
  53. typedef size_t size_type;
  54. typedef const _Ep* iterator;
  55. typedef const _Ep* const_iterator;
  56. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
  57. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 size_t size() const _NOEXCEPT { return __size_; }
  58. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* begin() const _NOEXCEPT { return __begin_; }
  59. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* end() const _NOEXCEPT { return __begin_ + __size_; }
  60. };
  61. template <class _Ep>
  62. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* begin(initializer_list<_Ep> __il) _NOEXCEPT {
  63. return __il.begin();
  64. }
  65. template <class _Ep>
  66. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Ep* end(initializer_list<_Ep> __il) _NOEXCEPT {
  67. return __il.end();
  68. }
  69. #endif // !defined(_LIBCPP_CXX03_LANG)
  70. } // namespace std
  71. #endif // _LIBCPP_INITIALIZER_LIST