[scudo] Group type traits into a single header (NFC) (#118888)

This commit is contained in:
ChiaHungDuan
2024-12-09 20:34:16 -08:00
committed by GitHub
parent cfbf809e93
commit 2c0b8b10dd
4 changed files with 50 additions and 40 deletions

View File

@@ -98,6 +98,7 @@ set(SCUDO_HEADERS
tsd_exclusive.h
tsd_shared.h
tsd.h
type_traits.h
vector.h
wrappers_c_checks.h
wrappers_c.h

View File

@@ -12,35 +12,7 @@
#include "condition_variable.h"
#include "internal_defs.h"
#include "secondary.h"
namespace {
template <typename T> struct removeConst {
using type = T;
};
template <typename T> struct removeConst<const T> {
using type = T;
};
// This is only used for SFINAE when detecting if a type is defined.
template <typename T> struct voidAdaptor {
using type = void;
};
// This is used for detecting the case that defines the flag with wrong type and
// it'll be viewed as undefined optional flag.
template <typename L, typename R> struct assertSameType {
template <typename, typename> struct isSame {
static constexpr bool value = false;
};
template <typename T> struct isSame<T, T> {
static constexpr bool value = true;
};
static_assert(isSame<L, R>::value, "Flag type mismatches");
using type = R;
};
} // namespace
#include "type_traits.h"
namespace scudo {

View File

@@ -10,17 +10,7 @@
#define SCUDO_LIST_H_
#include "internal_defs.h"
// TODO: Move the helpers to a header.
namespace {
template <typename T> struct isPointer {
static constexpr bool value = false;
};
template <typename T> struct isPointer<T *> {
static constexpr bool value = true;
};
} // namespace
#include "type_traits.h"
namespace scudo {

View File

@@ -0,0 +1,47 @@
//===-- type_traits.h -------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef SCUDO_TYPE_TRAITS_H_
#define SCUDO_TYPE_TRAITS_H_
namespace scudo {
template <typename T> struct removeConst {
using type = T;
};
template <typename T> struct removeConst<const T> {
using type = T;
};
// This is only used for SFINAE when detecting if a type is defined.
template <typename T> struct voidAdaptor {
using type = void;
};
template <typename L, typename R> struct assertSameType {
template <typename, typename> struct isSame {
static constexpr bool value = false;
};
template <typename T> struct isSame<T, T> {
static constexpr bool value = true;
};
static_assert(isSame<L, R>::value, "Type mismatches");
using type = R;
};
template <typename T> struct isPointer {
static constexpr bool value = false;
};
template <typename T> struct isPointer<T *> {
static constexpr bool value = true;
};
} // namespace scudo
#endif // SCUDO_TYPE_TRAITS_H_