libstdc++
array
Go to the documentation of this file.
00001 // <experimental/array> -*- C++ -*-
00002 
00003 // Copyright (C) 2015-2019 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file experimental/array
00026  *  This is a TS C++ Library header.
00027  */
00028 
00029 #ifndef _GLIBCXX_EXPERIMENTAL_ARRAY
00030 #define _GLIBCXX_EXPERIMENTAL_ARRAY 1
00031 
00032 #pragma GCC system_header
00033 
00034 #if __cplusplus >= 201402L
00035 
00036 #include <array>
00037 #include <experimental/type_traits>
00038 
00039 namespace std _GLIBCXX_VISIBILITY(default)
00040 {
00041 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00042 
00043 namespace experimental
00044 {
00045 inline namespace fundamentals_v2
00046 {
00047 #define __cpp_lib_experimental_make_array 201505
00048   /**
00049    * @defgroup make_array Array creation functions
00050    * @ingroup experimental
00051    *
00052    * Array creation functions as described in N4529,
00053    * Working Draft, C++ Extensions for Library Fundamentals, Version 2
00054    *
00055    * @{
00056    */
00057 
00058 template<typename _Dest, typename... _Types>
00059   struct __make_array_elem
00060   {
00061     using type = _Dest;
00062   };
00063 
00064 template<typename... _Types>
00065   struct __make_array_elem<void, _Types...>
00066   : common_type<_Types...>
00067   {
00068     template <typename>
00069       struct __is_reference_wrapper : false_type
00070       {};
00071 
00072     template <typename _Up>
00073       struct __is_reference_wrapper<reference_wrapper<_Up>> : true_type
00074       {};
00075 
00076     static_assert(!__or_<__is_reference_wrapper<decay_t<_Types>>...>::value,
00077                   "make_array must be used with an explicit target type when"
00078                   "any of the arguments is a reference_wrapper");
00079   };
00080 
00081 template <typename _Dest = void, typename... _Types>
00082   constexpr
00083   array<typename __make_array_elem<_Dest, _Types...>::type, sizeof...(_Types)>
00084   make_array(_Types&&... __t)
00085   {
00086     return {{ std::forward<_Types>(__t)... }};
00087   }
00088 
00089 template <typename _Tp, size_t _Nm, size_t... _Idx>
00090   constexpr array<remove_cv_t<_Tp>, _Nm>
00091   __to_array(_Tp (&__a)[_Nm], index_sequence<_Idx...>)
00092   {
00093     return {{__a[_Idx]...}};
00094   }
00095 
00096 template <typename _Tp, size_t _Nm>
00097   constexpr array<remove_cv_t<_Tp>, _Nm>
00098   to_array(_Tp (&__a)[_Nm])
00099   noexcept(is_nothrow_constructible<remove_cv_t<_Tp>, _Tp&>::value)
00100   {
00101     return __to_array(__a, make_index_sequence<_Nm>{});
00102   }
00103 
00104   // @} group make_array
00105 } // namespace fundamentals_v2
00106 } // namespace experimental
00107 
00108 _GLIBCXX_END_NAMESPACE_VERSION
00109 } // namespace std
00110 
00111 #endif // C++14
00112 
00113 #endif // _GLIBCXX_EXPERIMENTAL_ARRAY