folly/folly/lang/New.h

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <new>

#include <folly/CppAttributes.h>
#include <folly/Portability.h>
#include <folly/functional/Invoke.h>

namespace folly {

namespace detail {

#if defined(__cpp_aligned_new)
constexpr auto cpp_aligned_new_ =;
#else
constexpr auto cpp_aligned_new_ = false;
#endif

#if defined(__cpp_sized_deallocation)
constexpr auto cpp_sized_deallocation_ = __cpp_sized_deallocation >= 201309L;
#else
constexpr auto cpp_sized_deallocation_ =;
#endif

//  https://clang.llvm.org/docs/LanguageExtensions.html#builtin-operator-new-and-builtin-operator-delete

constexpr auto op_new_builtin_ =__builtin_operator_new) >= 201802L;
constexpr auto op_del_builtin_ =__builtin_operator_del) >= 201802L;

FOLLY_CREATE_QUAL_INVOKER(op_new_builtin_fn_, __builtin_operator_new);
FOLLY_CREATE_QUAL_INVOKER(op_new_library_fn_, ::operator new);

FOLLY_CREATE_QUAL_INVOKER(op_del_builtin_fn_, __builtin_operator_delete);
FOLLY_CREATE_QUAL_INVOKER(op_del_library_fn_, ::operator delete);

op_new_;

op_del_;

template <bool Usual, typename... A>
FOLLY_ERASE void do_op_del_sized_(
    void* const p, std::size_t const s, A const... a) {}

} // namespace detail

//  operator_new
struct operator_new_fn {};
inline constexpr operator_new_fn operator_new{};

//  operator_delete
struct operator_delete_fn {};
inline constexpr operator_delete_fn operator_delete{};

} // namespace folly