Skip to content

[libc][NFC] split type_traits / utility in separate files #65314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions libc/src/__support/CPP/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_FUNCTIONAL_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_FUNCTIONAL_H

#include "src/__support/CPP/type_traits.h"
#include "src/__support/CPP/utility.h"
#include "src/__support/CPP/type_traits/enable_if.h"
#include "src/__support/CPP/type_traits/is_convertible.h"
#include "src/__support/CPP/type_traits/is_same.h"
#include "src/__support/CPP/type_traits/is_void.h"
#include "src/__support/CPP/type_traits/remove_cvref.h"
#include "src/__support/CPP/type_traits/remove_reference.h"
#include "src/__support/CPP/utility/forward.h"
#include "src/__support/macros/attributes.h"

#include <stdint.h>
Expand All @@ -30,7 +35,7 @@ template <typename Ret, typename... Params> class function<Ret(Params...)> {
template <typename Callable>
LIBC_INLINE static Ret callback_fn(intptr_t callable, Params... params) {
return (*reinterpret_cast<Callable *>(callable))(
forward<Params>(params)...);
cpp::forward<Params>(params)...);
}

public:
Expand All @@ -42,18 +47,18 @@ template <typename Ret, typename... Params> class function<Ret(Params...)> {
LIBC_INLINE function(
Callable &&callable,
// This is not the copy-constructor.
enable_if_t<!is_same<remove_cvref_t<Callable>, function>::value> * =
enable_if_t<!cpp::is_same_v<remove_cvref_t<Callable>, function>> * =
nullptr,
// Functor must be callable and return a suitable type.
enable_if_t<is_void_v<Ret> ||
is_convertible_v<
enable_if_t<cpp::is_void_v<Ret> ||
cpp::is_convertible_v<
decltype(declval<Callable>()(declval<Params>()...)), Ret>>
* = nullptr)
: callback(callback_fn<remove_reference_t<Callable>>),
: callback(callback_fn<cpp::remove_reference_t<Callable>>),
callable(reinterpret_cast<intptr_t>(&callable)) {}

LIBC_INLINE Ret operator()(Params... params) const {
return callback(callable, forward<Params>(params)...);
return callback(callable, cpp::forward<Params>(params)...);
}

LIBC_INLINE explicit operator bool() const { return callback; }
Expand Down
Loading