Skip to content

Commit 5f71287

Browse files
committed
Expanded C++20 concepts, added C++23 std::unreachable, fixed issues with is_destructible
1 parent f26ea58 commit 5f71287

File tree

4 files changed

+75
-31
lines changed

4 files changed

+75
-31
lines changed

src/libcxx/include/concepts

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,56 @@
1-
// -*- C++ -*-
2-
#ifndef _EZCXX_CONCEPTS
3-
#define _EZCXX_CONCEPTS
4-
5-
#include <type_traits>
6-
7-
#pragma clang system_header
8-
9-
namespace std {
10-
11-
template <class _Tp, class _Up>
12-
concept same_as = is_same<_Tp, _Up>::value && is_same<_Up, _Tp>::value;
13-
14-
// arithmetic:
15-
16-
template <class _Tp>
17-
concept integral = is_integral_v<_Tp>;
18-
19-
template <class _Tp>
20-
concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
21-
22-
template <class _Tp>
23-
concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
24-
25-
template <class _Tp>
26-
concept floating_point = is_floating_point_v<_Tp>;
27-
28-
} // namespace std
29-
30-
#endif // _EZCXX_CONCEPTS
1+
// -*- C++ -*-
2+
#ifndef _EZCXX_CONCEPTS
3+
#define _EZCXX_CONCEPTS
4+
5+
#include <type_traits>
6+
7+
#pragma clang system_header
8+
9+
namespace std {
10+
11+
template<class _Tp, class _Up>
12+
concept same_as = is_same<_Tp, _Up>::value && is_same<_Up, _Tp>::value;
13+
14+
template<class _From, class _To>
15+
concept convertible_to =
16+
is_convertible_v<_From, _To> &&
17+
requires { static_cast<_To>(std::declval<_From>()); };
18+
19+
template <class _Dp, class _Bp>
20+
concept derived_from =
21+
is_base_of_v<_Bp, _Dp> &&
22+
is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
23+
24+
template<class _Tp>
25+
concept destructible = is_nothrow_destructible_v<_Tp>;
26+
27+
template<class _Tp, class... _Args>
28+
concept constructible_from =
29+
destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
30+
31+
template<class _Tp>
32+
concept integral = is_integral_v<_Tp>;
33+
34+
template<class _Tp>
35+
concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
36+
37+
template<class _Tp>
38+
concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
39+
40+
template<class _Tp>
41+
concept floating_point = is_floating_point_v<_Tp>;
42+
43+
template<class _Tp>
44+
concept move_constructible =
45+
constructible_from<_Tp, _Tp> && std::convertible_to<_Tp, _Tp>;
46+
47+
template<class _Tp>
48+
concept copy_constructible =
49+
move_constructible<_Tp> &&
50+
constructible_from<_Tp, _Tp&> && convertible_to<_Tp&, _Tp> &&
51+
constructible_from<_Tp, const _Tp&> && convertible_to<const _Tp&, _Tp> &&
52+
constructible_from<_Tp, const _Tp> && convertible_to<const _Tp, _Tp>;
53+
54+
} // namespace std
55+
56+
#endif // _EZCXX_CONCEPTS

src/libcxx/include/type_traits

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,20 +447,36 @@ template<class _Tp> using is_nothrow_move_assignable = is_nothrow_assignable<add
447447
add_rvalue_reference_t<_Tp>>;
448448
template<class _Tp> inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
449449

450+
/* Clang 16.0.0 required */
451+
#if 0
450452
#if __has_builtin(__is_destructible)
451453
template<class _Tp> inline constexpr bool is_destructible_v = __is_destructible(_Tp);
452454
template<class _Tp> using is_destructible = bool_constant<is_destructible_v<_Tp>>;
453455
#endif
456+
#elif __cplusplus >= 201907L
457+
template<typename _Tp> struct is_destructible
458+
: std::integral_constant<bool, requires(_Tp _Object) { _Object.~_Tp(); }>
459+
{};
460+
template<class _Tp> inline constexpr bool is_destructible_v = is_destructible<_Tp>::value;
461+
#endif
454462

455463
#if __has_builtin(__is_trivially_destructible)
456464
template<class _Tp> inline constexpr bool is_trivially_destructible_v = __is_trivially_destructible(_Tp);
457465
template<class _Tp> using is_trivially_destructible = bool_constant<is_trivially_destructible_v<_Tp>>;
458466
#endif
459467

468+
/* Clang 16.0.0 required */
469+
#if 0
460470
#if __has_builtin(__is_nothrow_destructible)
461471
template<class _Tp> inline constexpr bool is_nothrow_destructible_v = __is_nothrow_destructible(_Tp);
462472
template<class _Tp> using is_nothrow_destructible = bool_constant<is_nothrow_destructible_v<_Tp>>;
463473
#endif
474+
#elif __cplusplus >= 201907L
475+
template<typename _Tp> struct is_nothrow_destructible
476+
: std::integral_constant<bool, requires(_Tp _Object) { {_Object.~_Tp()} noexcept; }>
477+
{};
478+
template<class _Tp> inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<_Tp>::value;
479+
#endif
464480

465481
#if __has_builtin(__has_virtual_destructor)
466482
template<class _Tp> inline constexpr bool has_virtual_destructor_v = __has_virtual_destructor(_Tp);

src/libcxx/include/utility

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ template<class _Tp> _EZCXX_INLINE constexpr std::add_const_t<_Tp>& as_const(_Tp&
3333
template<class _Tp> _EZCXX_INLINE constexpr auto as_const(_Tp const&& __value) noexcept = delete;
3434
#endif // __cplusplus > 201103L
3535

36+
[[noreturn]] inline void unreachable() { __builtin_unreachable(); }
37+
3638
} // namespace std
3739

3840
#endif // _EZCXX_UTILITY

src/libcxx/include/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
// # define __cpp_lib_string_resize_and_overwrite 202110L
214214
// # define __cpp_lib_to_underlying 202102L
215215
// # define __cpp_lib_tuple_like 202207L
216-
// # define __cpp_lib_unreachable 202202L
216+
# define __cpp_lib_unreachable 202202L
217217
#endif // __cplusplus >= 202302L
218218

219219
#endif // _EZCXX_VERSION

0 commit comments

Comments
 (0)