Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Granularize parts of <type_traits>
`<type_traits>` is quite a large header, so I'll granularize it in a few steps. Reviewed By: ldionne, #libc Spies: libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D124755
- Loading branch information
1 parent
f0a61c2
commit eebc1fb
Showing
30 changed files
with
1,232 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 _LIBCPP___TYPE_TRAITS_ADD_POINTER_H | ||
#define _LIBCPP___TYPE_TRAITS_ADD_POINTER_H | ||
|
||
#include <__config> | ||
#include <__type_traits/is_referenceable.h> | ||
#include <__type_traits/is_same.h> | ||
#include <__type_traits/remove_cv.h> | ||
#include <__type_traits/remove_reference.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <class _Tp, | ||
bool = __is_referenceable<_Tp>::value || | ||
_IsSame<typename remove_cv<_Tp>::type, void>::value> | ||
struct __add_pointer_impl | ||
{typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type* type;}; | ||
template <class _Tp> struct __add_pointer_impl<_Tp, false> | ||
{typedef _LIBCPP_NODEBUG _Tp type;}; | ||
|
||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer | ||
{typedef _LIBCPP_NODEBUG typename __add_pointer_impl<_Tp>::type type;}; | ||
|
||
#if _LIBCPP_STD_VER > 11 | ||
template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type; | ||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_ADD_POINTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 _LIBCPP___TYPE_TRAITS_CONDITIONAL_H | ||
#define _LIBCPP___TYPE_TRAITS_CONDITIONAL_H | ||
|
||
#include <__config> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <bool _Bp, class _If, class _Then> | ||
struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;}; | ||
template <class _If, class _Then> | ||
struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {typedef _Then type;}; | ||
|
||
#if _LIBCPP_STD_VER > 11 | ||
template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type; | ||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_CONDITIONAL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 _LIBCPP___TYPE_TRAITS_DECAY_H | ||
#define _LIBCPP___TYPE_TRAITS_DECAY_H | ||
|
||
#include <__config> | ||
#include <__type_traits/add_pointer.h> | ||
#include <__type_traits/conditional.h> | ||
#include <__type_traits/integral_constant.h> | ||
#include <__type_traits/is_array.h> | ||
#include <__type_traits/is_function.h> | ||
#include <__type_traits/is_referenceable.h> | ||
#include <__type_traits/remove_cv.h> | ||
#include <__type_traits/remove_extent.h> | ||
#include <__type_traits/remove_reference.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <class _Up, bool> | ||
struct __decay { | ||
typedef _LIBCPP_NODEBUG typename remove_cv<_Up>::type type; | ||
}; | ||
|
||
template <class _Up> | ||
struct __decay<_Up, true> { | ||
public: | ||
typedef _LIBCPP_NODEBUG typename conditional | ||
< | ||
is_array<_Up>::value, | ||
typename remove_extent<_Up>::type*, | ||
typename conditional | ||
< | ||
is_function<_Up>::value, | ||
typename add_pointer<_Up>::type, | ||
typename remove_cv<_Up>::type | ||
>::type | ||
>::type type; | ||
}; | ||
|
||
template <class _Tp> | ||
struct _LIBCPP_TEMPLATE_VIS decay | ||
{ | ||
private: | ||
typedef _LIBCPP_NODEBUG typename remove_reference<_Tp>::type _Up; | ||
public: | ||
typedef _LIBCPP_NODEBUG typename __decay<_Up, __is_referenceable<_Up>::value>::type type; | ||
}; | ||
|
||
#if _LIBCPP_STD_VER > 11 | ||
template <class _Tp> using decay_t = typename decay<_Tp>::type; | ||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_DECAY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 _LIBCPP___TYPE_TRAITS_ENABLE_IF_H | ||
#define _LIBCPP___TYPE_TRAITS_ENABLE_IF_H | ||
|
||
#include <__config> | ||
#include <cstddef> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {}; | ||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;}; | ||
|
||
template <bool _Bp, class _Tp = void> using __enable_if_t _LIBCPP_NODEBUG = typename enable_if<_Bp, _Tp>::type; | ||
|
||
#if _LIBCPP_STD_VER > 11 | ||
template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type; | ||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_ENABLE_IF_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 _LIBCPP___TYPE_TRAITS_IS_ARRAY_H | ||
#define _LIBCPP___TYPE_TRAITS_IS_ARRAY_H | ||
|
||
#include <__config> | ||
#include <__type_traits/integral_constant.h> | ||
#include <cstddef> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
// TODO: Clang incorrectly reports that __is_array is true for T[0]. | ||
// Re-enable the branch once https://llvm.org/PR54705 is fixed. | ||
#if __has_keyword(__is_array) && 0 | ||
|
||
template <class _Tp> | ||
struct _LIBCPP_TEMPLATE_VIS is_array : _BoolConstant<__is_array(_Tp)> { }; | ||
|
||
#if _LIBCPP_STD_VER > 14 | ||
template <class _Tp> | ||
inline constexpr bool is_array_v = __is_array(_Tp); | ||
#endif | ||
|
||
#else | ||
|
||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array | ||
: public false_type {}; | ||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]> | ||
: public true_type {}; | ||
template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]> | ||
: public true_type {}; | ||
|
||
#if _LIBCPP_STD_VER > 14 | ||
template <class _Tp> | ||
inline constexpr bool is_array_v = is_array<_Tp>::value; | ||
#endif | ||
|
||
#endif // __has_keyword(__is_array) | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_IS_ARRAY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 _LIBCPP___TYPE_TRAITS_IS_BASE_OF_H | ||
#define _LIBCPP___TYPE_TRAITS_IS_BASE_OF_H | ||
|
||
#include <__config> | ||
#include <__type_traits/integral_constant.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <class _Bp, class _Dp> | ||
struct _LIBCPP_TEMPLATE_VIS is_base_of | ||
: public integral_constant<bool, __is_base_of(_Bp, _Dp)> {}; | ||
|
||
#if _LIBCPP_STD_VER > 14 | ||
template <class _Bp, class _Dp> | ||
inline constexpr bool is_base_of_v = is_base_of<_Bp, _Dp>::value; | ||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_IS_BASE_OF_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 _LIBCPP___TYPE_TRAITS_IS_CONST_H | ||
#define _LIBCPP___TYPE_TRAITS_IS_CONST_H | ||
|
||
#include <__config> | ||
#include <__type_traits/integral_constant.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if __has_keyword(__is_const) | ||
|
||
template <class _Tp> | ||
struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { }; | ||
|
||
#if _LIBCPP_STD_VER > 14 | ||
template <class _Tp> | ||
inline constexpr bool is_const_v = __is_const(_Tp); | ||
#endif | ||
|
||
#else | ||
|
||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {}; | ||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {}; | ||
|
||
#if _LIBCPP_STD_VER > 14 | ||
template <class _Tp> | ||
inline constexpr bool is_const_v = is_const<_Tp>::value; | ||
#endif | ||
|
||
#endif // __has_keyword(__is_const) | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_IS_CONST_H |
Oops, something went wrong.