2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <folly/Traits.h>
20 #include <type_traits>
25 namespace array_detail {
27 struct is_ref_wrapper : std::false_type {};
29 struct is_ref_wrapper<std::reference_wrapper<T>> : std::true_type {};
32 using not_ref_wrapper =
33 folly::Negation<is_ref_wrapper<typename std::decay<T>::type>>;
35 template <typename D, typename...>
36 struct return_type_helper {
39 template <typename... TList>
40 struct return_type_helper<void, TList...> {
42 folly::Conjunction<not_ref_wrapper<TList>...>::value,
43 "TList cannot contain reference_wrappers when D is void");
44 using type = typename std::common_type<TList...>::type;
47 template <typename D, typename... TList>
48 using return_type = std::
49 array<typename return_type_helper<D, TList...>::type, sizeof...(TList)>;
52 template <typename D = void, typename... TList>
53 constexpr array_detail::return_type<D, TList...> make_array(TList&&... t) {
55 typename array_detail::return_type_helper<D, TList...>::type;
56 return {{static_cast<value_type>(std::forward<TList>(t))...}};