Skip to content

Commit 2c0b8b1

Browse files
authored
[scudo] Group type traits into a single header (NFC) (#118888)
1 parent cfbf809 commit 2c0b8b1

File tree

4 files changed

+50
-40
lines changed

4 files changed

+50
-40
lines changed

compiler-rt/lib/scudo/standalone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ set(SCUDO_HEADERS
9898
tsd_exclusive.h
9999
tsd_shared.h
100100
tsd.h
101+
type_traits.h
101102
vector.h
102103
wrappers_c_checks.h
103104
wrappers_c.h

compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,7 @@
1212
#include "condition_variable.h"
1313
#include "internal_defs.h"
1414
#include "secondary.h"
15-
16-
namespace {
17-
18-
template <typename T> struct removeConst {
19-
using type = T;
20-
};
21-
template <typename T> struct removeConst<const T> {
22-
using type = T;
23-
};
24-
25-
// This is only used for SFINAE when detecting if a type is defined.
26-
template <typename T> struct voidAdaptor {
27-
using type = void;
28-
};
29-
30-
// This is used for detecting the case that defines the flag with wrong type and
31-
// it'll be viewed as undefined optional flag.
32-
template <typename L, typename R> struct assertSameType {
33-
template <typename, typename> struct isSame {
34-
static constexpr bool value = false;
35-
};
36-
template <typename T> struct isSame<T, T> {
37-
static constexpr bool value = true;
38-
};
39-
static_assert(isSame<L, R>::value, "Flag type mismatches");
40-
using type = R;
41-
};
42-
43-
} // namespace
15+
#include "type_traits.h"
4416

4517
namespace scudo {
4618

compiler-rt/lib/scudo/standalone/list.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@
1010
#define SCUDO_LIST_H_
1111

1212
#include "internal_defs.h"
13-
14-
// TODO: Move the helpers to a header.
15-
namespace {
16-
template <typename T> struct isPointer {
17-
static constexpr bool value = false;
18-
};
19-
20-
template <typename T> struct isPointer<T *> {
21-
static constexpr bool value = true;
22-
};
23-
} // namespace
13+
#include "type_traits.h"
2414

2515
namespace scudo {
2616

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===-- type_traits.h -------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef SCUDO_TYPE_TRAITS_H_
10+
#define SCUDO_TYPE_TRAITS_H_
11+
12+
namespace scudo {
13+
14+
template <typename T> struct removeConst {
15+
using type = T;
16+
};
17+
template <typename T> struct removeConst<const T> {
18+
using type = T;
19+
};
20+
21+
// This is only used for SFINAE when detecting if a type is defined.
22+
template <typename T> struct voidAdaptor {
23+
using type = void;
24+
};
25+
26+
template <typename L, typename R> struct assertSameType {
27+
template <typename, typename> struct isSame {
28+
static constexpr bool value = false;
29+
};
30+
template <typename T> struct isSame<T, T> {
31+
static constexpr bool value = true;
32+
};
33+
static_assert(isSame<L, R>::value, "Type mismatches");
34+
using type = R;
35+
};
36+
37+
template <typename T> struct isPointer {
38+
static constexpr bool value = false;
39+
};
40+
41+
template <typename T> struct isPointer<T *> {
42+
static constexpr bool value = true;
43+
};
44+
45+
} // namespace scudo
46+
47+
#endif // SCUDO_TYPE_TRAITS_H_

0 commit comments

Comments
 (0)