1 | /* |
2 | * Copyright 2018-present 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 | |
17 | #pragma once |
18 | |
19 | #include <type_traits> |
20 | |
21 | #include <folly/Traits.h> |
22 | |
23 | namespace folly { |
24 | namespace detail { |
25 | |
26 | struct DefaultTag {}; |
27 | |
28 | template <typename T> |
29 | struct DefaultMake { |
30 | struct Heap { |
31 | std::unique_ptr<T> ptr{std::make_unique<T>()}; |
32 | /* implicit */ operator T&() { |
33 | return *ptr; |
34 | } |
35 | }; |
36 | |
37 | using is_returnable = StrictDisjunction< |
38 | bool_constant<__cplusplus >= 201703ULL>, |
39 | std::is_copy_constructible<T>, |
40 | std::is_move_constructible<T>>; |
41 | using type = std::conditional_t<is_returnable::value, T, Heap>; |
42 | |
43 | type operator()() const { |
44 | return type(); |
45 | } |
46 | }; |
47 | |
48 | template <typename...> |
49 | struct TypeTuple {}; |
50 | |
51 | } // namespace detail |
52 | } // namespace folly |
53 | |