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