Skip to content

Commit 4acc3ff

Browse files
committed
[reland][libc][NFC] split type_traits / utility in separate files (#65314)
`type_traits` and `utility` refer to each other in their implementations. Also `type_traits` starts to become too big to be manageable. This PR splits each function into individual files. FTR this is [how libcxx handles large headers as well](https://github.com/llvm/llvm-project/tree/main/libcxx/include/__type_traits). The reland adds two missing functions : is_destructible_v and is_reference_v
1 parent 6cfb411 commit 4acc3ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1503
-395
lines changed

libc/src/__support/CPP/functional.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_FUNCTIONAL_H
1010
#define LLVM_LIBC_SRC_SUPPORT_CPP_FUNCTIONAL_H
1111

12-
#include "src/__support/CPP/type_traits.h"
13-
#include "src/__support/CPP/utility.h"
12+
#include "src/__support/CPP/type_traits/enable_if.h"
13+
#include "src/__support/CPP/type_traits/is_convertible.h"
14+
#include "src/__support/CPP/type_traits/is_same.h"
15+
#include "src/__support/CPP/type_traits/is_void.h"
16+
#include "src/__support/CPP/type_traits/remove_cvref.h"
17+
#include "src/__support/CPP/type_traits/remove_reference.h"
18+
#include "src/__support/CPP/utility/forward.h"
1419
#include "src/__support/macros/attributes.h"
1520

1621
#include <stdint.h>
@@ -30,7 +35,7 @@ template <typename Ret, typename... Params> class function<Ret(Params...)> {
3035
template <typename Callable>
3136
LIBC_INLINE static Ret callback_fn(intptr_t callable, Params... params) {
3237
return (*reinterpret_cast<Callable *>(callable))(
33-
forward<Params>(params)...);
38+
cpp::forward<Params>(params)...);
3439
}
3540

3641
public:
@@ -42,18 +47,18 @@ template <typename Ret, typename... Params> class function<Ret(Params...)> {
4247
LIBC_INLINE function(
4348
Callable &&callable,
4449
// This is not the copy-constructor.
45-
enable_if_t<!is_same<remove_cvref_t<Callable>, function>::value> * =
50+
enable_if_t<!cpp::is_same_v<remove_cvref_t<Callable>, function>> * =
4651
nullptr,
4752
// Functor must be callable and return a suitable type.
48-
enable_if_t<is_void_v<Ret> ||
49-
is_convertible_v<
53+
enable_if_t<cpp::is_void_v<Ret> ||
54+
cpp::is_convertible_v<
5055
decltype(declval<Callable>()(declval<Params>()...)), Ret>>
5156
* = nullptr)
52-
: callback(callback_fn<remove_reference_t<Callable>>),
57+
: callback(callback_fn<cpp::remove_reference_t<Callable>>),
5358
callable(reinterpret_cast<intptr_t>(&callable)) {}
5459

5560
LIBC_INLINE Ret operator()(Params... params) const {
56-
return callback(callable, forward<Params>(params)...);
61+
return callback(callable, cpp::forward<Params>(params)...);
5762
}
5863

5964
LIBC_INLINE explicit operator bool() const { return callback; }

0 commit comments

Comments
 (0)