Skip to content

Commit 74971db

Browse files
authored
[libc] Add is_scalar (#65740)
Adds the is_scalar traits based on implementation in https://en.cppreference.com/w/cpp/types/is_scalar
1 parent 4871a9c commit 74971db

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

libc/src/__support/CPP/type_traits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "src/__support/CPP/type_traits/is_reference.h"
3737
#include "src/__support/CPP/type_traits/is_rvalue_reference.h"
3838
#include "src/__support/CPP/type_traits/is_same.h"
39+
#include "src/__support/CPP/type_traits/is_scalar.h"
3940
#include "src/__support/CPP/type_traits/is_signed.h"
4041
#include "src/__support/CPP/type_traits/is_trivially_constructible.h"
4142
#include "src/__support/CPP/type_traits/is_trivially_copyable.h"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===-- is_scalar type_traits -----------------------------------*- 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+
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H
9+
#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H
10+
11+
#include "src/__support/CPP/type_traits/bool_constant.h"
12+
#include "src/__support/CPP/type_traits/is_arithmetic.h"
13+
#include "src/__support/CPP/type_traits/is_enum.h"
14+
#include "src/__support/CPP/type_traits/is_member_pointer.h"
15+
#include "src/__support/CPP/type_traits/is_null_pointer.h"
16+
#include "src/__support/CPP/type_traits/is_pointer.h"
17+
#include "src/__support/macros/attributes.h"
18+
19+
namespace __llvm_libc::cpp {
20+
21+
// is_scalar
22+
template <class T>
23+
struct is_scalar
24+
: cpp::bool_constant<cpp::is_arithmetic_v<T> || cpp::is_enum_v<T> ||
25+
cpp::is_pointer_v<T> || cpp::is_member_pointer_v<T> ||
26+
cpp::is_null_pointer_v<T>> {};
27+
template <class T>
28+
LIBC_INLINE_VAR constexpr bool is_scalar_v = is_scalar<T>::value;
29+
30+
} // namespace __llvm_libc::cpp
31+
32+
#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ libc_support_library(
313313
"src/__support/CPP/type_traits/is_reference.h",
314314
"src/__support/CPP/type_traits/is_rvalue_reference.h",
315315
"src/__support/CPP/type_traits/is_same.h",
316+
"src/__support/CPP/type_traits/is_scalar.h",
316317
"src/__support/CPP/type_traits/is_signed.h",
317318
"src/__support/CPP/type_traits/is_trivially_constructible.h",
318319
"src/__support/CPP/type_traits/is_trivially_copyable.h",

0 commit comments

Comments
 (0)