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