initializer_list 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_COMPILER_MSVC) && !defined(__clang__)
  37. // save __cpp_lib_concepts because it can be redefined inside MSVC standard headers
  38. #pragma push_macro("__cpp_lib_concepts")
  39. #include Y_MSVC_INCLUDE_NEXT(yvals.h)
  40. #pragma pop_macro("__cpp_lib_concepts")
  41. #include Y_MSVC_INCLUDE_NEXT(initializer_list)
  42. #else
  43. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  44. # pragma GCC system_header
  45. #endif
  46. namespace std // purposefully not versioned
  47. {
  48. #ifndef _LIBCPP_CXX03_LANG
  49. template<class _Ep>
  50. class _LIBCPP_TEMPLATE_VIS initializer_list
  51. {
  52. const _Ep* __begin_;
  53. size_t __size_;
  54. _LIBCPP_INLINE_VISIBILITY
  55. _LIBCPP_CONSTEXPR_AFTER_CXX11
  56. initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
  57. : __begin_(__b),
  58. __size_(__s)
  59. {}
  60. public:
  61. typedef _Ep value_type;
  62. typedef const _Ep& reference;
  63. typedef const _Ep& const_reference;
  64. typedef size_t size_type;
  65. typedef const _Ep* iterator;
  66. typedef const _Ep* const_iterator;
  67. _LIBCPP_INLINE_VISIBILITY
  68. _LIBCPP_CONSTEXPR_AFTER_CXX11
  69. initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
  70. initializer_list(const initializer_list&) = default;
  71. initializer_list(initializer_list&&) = default;
  72. initializer_list& operator=(const initializer_list&) = delete;
  73. initializer_list& operator=(initializer_list&&) = delete;
  74. _LIBCPP_INLINE_VISIBILITY
  75. _LIBCPP_CONSTEXPR_AFTER_CXX11
  76. size_t size() const _NOEXCEPT {return __size_;}
  77. _LIBCPP_INLINE_VISIBILITY
  78. _LIBCPP_CONSTEXPR_AFTER_CXX11
  79. const _Ep* begin() const _NOEXCEPT {return __begin_;}
  80. _LIBCPP_INLINE_VISIBILITY
  81. _LIBCPP_CONSTEXPR_AFTER_CXX11
  82. const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
  83. };
  84. template<class _Ep>
  85. inline _LIBCPP_INLINE_VISIBILITY
  86. _LIBCPP_CONSTEXPR_AFTER_CXX11
  87. const _Ep*
  88. begin(initializer_list<_Ep> __il) _NOEXCEPT
  89. {
  90. return __il.begin();
  91. }
  92. template<class _Ep>
  93. inline _LIBCPP_INLINE_VISIBILITY
  94. _LIBCPP_CONSTEXPR_AFTER_CXX11
  95. const _Ep*
  96. end(initializer_list<_Ep> __il) _NOEXCEPT
  97. {
  98. return __il.end();
  99. }
  100. #endif // !defined(_LIBCPP_CXX03_LANG)
  101. } // namespace std
  102. #endif // _LIBCPP_COMPILER_MSVC
  103. #endif // _LIBCPP_INITIALIZER_LIST