mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 22:06:38 +00:00

This is a basic implementation of P2719: "Type-aware allocation and deallocation functions" described at http://wg21.link/P2719 The proposal includes some more details but the basic change in functionality is the addition of support for an additional implicit parameter in operators `new` and `delete` to act as a type tag. Tag is of type `std::type_identity<T>` where T is the concrete type being allocated. So for example, a custom type specific allocator for `int` say can be provided by the declaration of void *operator new(std::type_identity<int>, size_t, std::align_val_t); void operator delete(std::type_identity<int>, void*, size_t, std::align_val_t); However this becomes more powerful by specifying templated declarations, for example template <typename T> void *operator new(std::type_identity<T>, size_t, std::align_val_t); template <typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t);); Where the operators being resolved will be the concrete type being operated over (NB. A completely unconstrained global definition as above is not recommended as it triggers many problems similar to a general override of the global operators). These type aware operators can be declared as either free functions or in class, and can be specified with or without the other implicit parameters, with overload resolution performed according to the existing standard parameter prioritisation, only with type parameterised operators having higher precedence than non-type aware operators. The only exception is destroying_delete which for reasons discussed in the paper we do not support type-aware variants by default.
49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify -fblocks -Wno-unreachable-code -Wno-unused-value
|
|
#ifndef STD_COROUTINE_H
|
|
#define STD_COROUTINE_H
|
|
|
|
namespace std {
|
|
|
|
template<typename T> struct remove_reference { typedef T type; };
|
|
template<typename T> struct remove_reference<T &> { typedef T type; };
|
|
template<typename T> struct remove_reference<T &&> { typedef T type; };
|
|
|
|
template<typename T>
|
|
typename remove_reference<T>::type &&move(T &&t) noexcept;
|
|
|
|
struct input_iterator_tag {};
|
|
struct forward_iterator_tag : public input_iterator_tag {};
|
|
|
|
template <class Ret, typename... T>
|
|
struct coroutine_traits { using promise_type = typename Ret::promise_type; };
|
|
|
|
template <class Promise = void>
|
|
struct coroutine_handle {
|
|
static coroutine_handle from_address(void *) noexcept;
|
|
static coroutine_handle from_promise(Promise &promise);
|
|
constexpr void* address() const noexcept;
|
|
};
|
|
template <>
|
|
struct coroutine_handle<void> {
|
|
template <class PromiseType>
|
|
coroutine_handle(coroutine_handle<PromiseType>) noexcept;
|
|
static coroutine_handle from_address(void *);
|
|
constexpr void* address() const noexcept;
|
|
};
|
|
|
|
struct suspend_always {
|
|
bool await_ready() noexcept { return false; }
|
|
void await_suspend(coroutine_handle<>) noexcept {}
|
|
void await_resume() noexcept {}
|
|
};
|
|
|
|
struct suspend_never {
|
|
bool await_ready() noexcept { return true; }
|
|
void await_suspend(coroutine_handle<>) noexcept {}
|
|
void await_resume() noexcept {}
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
#endif // STD_COROUTINE_H
|