libstdc++
|
00001 // <experimental/array> -*- C++ -*- 00002 00003 // Copyright (C) 2015-2017 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 <= 201103L 00035 # include <bits/c++14_warning.h> 00036 #else 00037 00038 #include <array> 00039 #include <experimental/type_traits> 00040 00041 namespace std _GLIBCXX_VISIBILITY(default) 00042 { 00043 namespace experimental 00044 { 00045 inline namespace fundamentals_v2 00046 { 00047 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00048 00049 #define __cpp_lib_experimental_make_array 201505 00050 /** 00051 * @defgroup make_array Array creation functions 00052 * @ingroup experimental 00053 * 00054 * Array creation functions as described in N4529, 00055 * Working Draft, C++ Extensions for Library Fundamentals, Version 2 00056 * 00057 * @{ 00058 */ 00059 00060 template<typename _Dest, typename... _Types> 00061 struct __make_array_elem 00062 { 00063 using type = _Dest; 00064 }; 00065 00066 template<typename... _Types> 00067 struct __make_array_elem<void, _Types...> 00068 : common_type<_Types...> 00069 { 00070 template <typename> 00071 struct __is_reference_wrapper : false_type 00072 {}; 00073 00074 template <typename _Up> 00075 struct __is_reference_wrapper<reference_wrapper<_Up>> : true_type 00076 {}; 00077 00078 static_assert(!__or_<__is_reference_wrapper<decay_t<_Types>>...>::value, 00079 "make_array must be used with an explicit target type when" 00080 "any of the arguments is a reference_wrapper"); 00081 }; 00082 00083 template <typename _Dest = void, typename... _Types> 00084 constexpr 00085 array<typename __make_array_elem<_Dest, _Types...>::type, sizeof...(_Types)> 00086 make_array(_Types&&... __t) 00087 { 00088 return {{ std::forward<_Types>(__t)... }}; 00089 } 00090 00091 template <typename _Tp, size_t _Nm, size_t... _Idx> 00092 constexpr array<remove_cv_t<_Tp>, _Nm> 00093 __to_array(_Tp (&__a)[_Nm], index_sequence<_Idx...>) 00094 { 00095 return {{__a[_Idx]...}}; 00096 } 00097 00098 template <typename _Tp, size_t _Nm> 00099 constexpr array<remove_cv_t<_Tp>, _Nm> 00100 to_array(_Tp (&__a)[_Nm]) 00101 noexcept(is_nothrow_constructible<remove_cv_t<_Tp>, _Tp&>::value) 00102 { 00103 return __to_array(__a, make_index_sequence<_Nm>{}); 00104 } 00105 00106 // @} group make_array 00107 _GLIBCXX_END_NAMESPACE_VERSION 00108 } // namespace fundamentals_v2 00109 } // namespace experimental 00110 00111 } // namespace std 00112 00113 #endif // C++14 00114 00115 #endif // _GLIBCXX_EXPERIMENTAL_ARRAY