1 //===----------------------------------------------------------------------===//
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 _LIBCPP___TYPE_TRAITS_IS_SCALAR_H
10 #define _LIBCPP___TYPE_TRAITS_IS_SCALAR_H
11 
12 #include <__config>
13 #include <__type_traits/integral_constant.h>
14 #include <__type_traits/is_arithmetic.h>
15 #include <__type_traits/is_enum.h>
16 #include <__type_traits/is_member_pointer.h>
17 #include <__type_traits/is_null_pointer.h>
18 #include <__type_traits/is_pointer.h>
19 
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #  pragma GCC system_header
22 #endif
23 
24 _LIBCPP_BEGIN_NAMESPACE_STD
25 
26 #if __has_builtin(__is_scalar)
27 
28 template<class _Tp>
29 struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
30 
31 #if _LIBCPP_STD_VER > 14
32 template <class _Tp>
33 inline constexpr bool is_scalar_v = __is_scalar(_Tp);
34 #endif
35 
36 #else // __has_builtin(__is_scalar)
37 
38 template <class _Tp> struct __is_block : false_type {};
39 #if defined(_LIBCPP_HAS_EXTENSION_BLOCKS)
40 template <class _Rp, class ..._Args> struct __is_block<_Rp (^)(_Args...)> : true_type {};
41 #endif
42 
43 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
44     : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
45                                      is_member_pointer<_Tp>::value ||
46                                      is_pointer<_Tp>::value        ||
47                                      __is_nullptr_t<_Tp>::value    ||
48                                      __is_block<_Tp>::value        ||
49                                      is_enum<_Tp>::value           > {};
50 
51 template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
52 
53 #if _LIBCPP_STD_VER > 14
54 template <class _Tp>
55 inline constexpr bool is_scalar_v = is_scalar<_Tp>::value;
56 #endif
57 
58 #endif // __has_builtin(__is_scalar)
59 
60 _LIBCPP_END_NAMESPACE_STD
61 
62 #endif // _LIBCPP___TYPE_TRAITS_IS_SCALAR_H
63