Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // <experimental/array> -*- C++ -*-
  2. // Copyright (C) 2015-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file experimental/array
  21. * This is a TS C++ Library header.
  22. * @ingroup libfund-ts
  23. */
  24. #ifndef _GLIBCXX_EXPERIMENTAL_ARRAY
  25. #define _GLIBCXX_EXPERIMENTAL_ARRAY 1
  26. #pragma GCC system_header
  27. #if __cplusplus >= 201402L
  28. #include <array>
  29. #include <experimental/type_traits>
  30. namespace std _GLIBCXX_VISIBILITY(default)
  31. {
  32. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  33. namespace experimental
  34. {
  35. inline namespace fundamentals_v2
  36. {
  37. #define __cpp_lib_experimental_make_array 201505
  38. /**
  39. * @defgroup make_array Array creation functions
  40. * @ingroup libfund-ts
  41. *
  42. * Array creation functions as described in N4529,
  43. * Working Draft, C++ Extensions for Library Fundamentals, Version 2
  44. *
  45. * @{
  46. */
  47. template<typename _Dest, typename... _Types>
  48. struct __make_array_elem
  49. {
  50. using type = _Dest;
  51. };
  52. template<typename... _Types>
  53. struct __make_array_elem<void, _Types...>
  54. : common_type<_Types...>
  55. {
  56. template <typename>
  57. struct __is_reference_wrapper : false_type
  58. {};
  59. template <typename _Up>
  60. struct __is_reference_wrapper<reference_wrapper<_Up>> : true_type
  61. {};
  62. static_assert(!__or_<__is_reference_wrapper<decay_t<_Types>>...>::value,
  63. "make_array must be used with an explicit target type when"
  64. "any of the arguments is a reference_wrapper");
  65. };
  66. /// Create a std::array from a variable-length list of arguments.
  67. template <typename _Dest = void, typename... _Types>
  68. constexpr
  69. array<typename __make_array_elem<_Dest, _Types...>::type, sizeof...(_Types)>
  70. make_array(_Types&&... __t)
  71. {
  72. return {{ std::forward<_Types>(__t)... }};
  73. }
  74. template <typename _Tp, size_t _Nm, size_t... _Idx>
  75. constexpr array<remove_cv_t<_Tp>, _Nm>
  76. __to_array(_Tp (&__a)[_Nm], index_sequence<_Idx...>)
  77. {
  78. return {{__a[_Idx]...}};
  79. }
  80. /// Create a std::array from an array.
  81. template <typename _Tp, size_t _Nm>
  82. constexpr array<remove_cv_t<_Tp>, _Nm>
  83. to_array(_Tp (&__a)[_Nm])
  84. noexcept(is_nothrow_constructible<remove_cv_t<_Tp>, _Tp&>::value)
  85. {
  86. return experimental::__to_array(__a, make_index_sequence<_Nm>{});
  87. }
  88. // @} group make_array
  89. } // namespace fundamentals_v2
  90. } // namespace experimental
  91. _GLIBCXX_END_NAMESPACE_VERSION
  92. } // namespace std
  93. #endif // C++14
  94. #endif // _GLIBCXX_EXPERIMENTAL_ARRAY