Revert D4832473: [Folly] Disable EnvUtil::setAsCurrentEnvironment() on platforms...
[folly.git] / folly / Array.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #pragma once
17
18 #include <folly/Traits.h>
19 #include <array>
20 #include <type_traits>
21 #include <utility>
22
23 namespace folly {
24
25 namespace array_detail {
26 template <typename>
27 struct is_ref_wrapper : std::false_type {};
28 template <typename T>
29 struct is_ref_wrapper<std::reference_wrapper<T>> : std::true_type {};
30
31 template <typename T>
32 using not_ref_wrapper =
33     folly::Negation<is_ref_wrapper<typename std::decay<T>::type>>;
34
35 template <typename D, typename...>
36 struct return_type_helper {
37   using type = D;
38 };
39 template <typename... TList>
40 struct return_type_helper<void, TList...> {
41   static_assert(
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;
45 };
46
47 template <typename D, typename... TList>
48 using return_type = std::
49     array<typename return_type_helper<D, TList...>::type, sizeof...(TList)>;
50 } // !array_detail
51
52 template <typename D = void, typename... TList>
53 constexpr array_detail::return_type<D, TList...> make_array(TList&&... t) {
54   using value_type =
55       typename array_detail::return_type_helper<D, TList...>::type;
56   return {{static_cast<value_type>(std::forward<TList>(t))...}};
57 }
58
59 } // !folly