Skip to content

Commit 87c907e

Browse files
committed
[libc++][type_traits] P2647R1: A trait for implicit lifetime types
Implements P2674R1: https://wg21.link/P2674R1 - https://eel.is/c++draft/type.traits - https://eel.is/c++draft/meta.type.synop - https://eel.is/c++draft/meta.unary.prop - https://eel.is/c++draft/support.limits - https://eel.is/c++draft/version.syn Implementation details: - Uses compiler intrinsic `__builtin_is_implicit_lifetime`: - #101807 - Tests based on: - https://github.com/llvm/llvm-project/blob/d213981c80626698a07b11ce872acba098a863d4/clang/test/SemaCXX/type-traits.cpp#L1989 References: - Implicit-lifetime - Implicit-lifetime types [basic.types.general]/9: https://eel.is/c++draft/basic.types.general - Implicit-lifetime class [class.prop]/9: https://eel.is/c++draft/class.prop - P0593R6 Implicit creation of objects for low-level object manipulation: https://wg21.link/P0593R6 - P1010R1 Container support for implicit lifetime types: https://wg21.link/P1010R1 - P0593R6 Implicit creation of objects for low-level object manipulation: https://wg21.link/P0593R6 Closes: #105259
1 parent ec58817 commit 87c907e

File tree

5 files changed

+457
-0
lines changed

5 files changed

+457
-0
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ set(files
778778
__type_traits/is_floating_point.h
779779
__type_traits/is_function.h
780780
__type_traits/is_fundamental.h
781+
__type_traits/is_implicit_lifetime.h
781782
__type_traits/is_implicitly_default_constructible.h
782783
__type_traits/is_integral.h
783784
__type_traits/is_literal_type.h
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_IMPLICIT_LIFETIME_H
10+
#define _LIBCPP___TYPE_TRAITS_IS_IMPLICIT_LIFETIME_H
11+
12+
#include <__config>
13+
#include <__type_traits/integral_constant.h>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
#if _LIBCPP_STD_VER >= 23
22+
# if __has_builtin(__builtin_is_implicit_lifetime)
23+
24+
template <class _Tp>
25+
struct _LIBCPP_TEMPLATE_VIS is_implicit_lifetime : public bool_constant<__builtin_is_implicit_lifetime(_Tp)> {};
26+
27+
template <class _Tp>
28+
inline constexpr bool is_implicit_lifetime_v = __builtin_is_implicit_lifetime(_Tp);
29+
30+
# else
31+
32+
template <typename _Tp>
33+
struct is_implicit_lifetime
34+
: std::disjunction< std::is_scalar<_Tp>,
35+
std::is_array<_Tp>,
36+
std::is_aggregate<_Tp>,
37+
std::conjunction< std::is_trivially_destructible<_Tp>,
38+
std::disjunction< std::is_trivially_default_constructible<_Tp>,
39+
std::is_trivially_copy_constructible<_Tp>,
40+
std::is_trivially_move_constructible<_Tp>>>> {};
41+
42+
template <class _Tp>
43+
inline constexpr bool is_implicit_lifetime_v = is_implicit_lifetime<_Tp>::value;
44+
45+
# endif
46+
#endif
47+
48+
_LIBCPP_END_NAMESPACE_STD
49+
50+
#endif // _LIBCPP___TYPE_TRAITS_IS_IMPLICIT_LIFETIME_H

libcxx/include/type_traits

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ namespace std
137137
template <class T> struct is_nothrow_swappable; // C++17
138138
template <class T> struct is_nothrow_destructible;
139139
140+
template<class T> struct is_implicit_lifetime; // Since C++23
141+
140142
template <class T> struct has_virtual_destructor;
141143
142144
template<class T> struct has_unique_object_representations; // C++17
@@ -374,6 +376,8 @@ namespace std
374376
= is_nothrow_swappable<T>::value; // C++17
375377
template <class T> inline constexpr bool is_nothrow_destructible_v
376378
= is_nothrow_destructible<T>::value; // C++17
379+
template<class T>
380+
constexpr bool is_implicit_lifetime_v = is_implicit_lifetime<T>::value; // Since C++23
377381
template <class T> inline constexpr bool has_virtual_destructor_v
378382
= has_virtual_destructor<T>::value; // C++17
379383
template<class T> inline constexpr bool has_unique_object_representations_v // C++17
@@ -517,6 +521,10 @@ namespace std
517521
# include <__type_traits/unwrap_ref.h>
518522
#endif
519523

524+
#if _LIBCPP_STD_VER >= 23
525+
# include <__type_traits/is_implicit_lifetime.h>
526+
#endif
527+
520528
#include <version>
521529

522530
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

0 commit comments

Comments
 (0)