Skip to content

Conversation

@ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Mar 14, 2025

Changes:

  • expanded <type_traits>
  • added to <concepts>
  • added C++23 std::unreachable to <utility>

I have added to <type_traits> by replacing __has_feature(is_foo) to __has_builtin(__is_foo). From this, almost all of C++17 <type_traits> has been implemented except for:

/* C++11 */
common_type
aligned_storage
aligned_union
result_of
is_trivially_copy_assignable
is_trivially_move_assignable
make_signed
make_unsigned
is_destructable // works in C++20, requires Clang 16 to work in C++11
is_nothrow_destructable // works in C++20, requires Clang 16 to work in C++11
/* C++17 */
is_swappable
is_nothrow_swappable
invoke_result

I also replaced existing functions in <type_traits> with builtins if possible. I still need to do testing to ensure that all transformations are correct.

__has_builtin is the same as __has_feature, except that the latter is "deprecated", so it won't return true for newer builtins https://releases.llvm.org/15.0.0/tools/clang/docs/LanguageExtensions.html#builtin-functions

There are multiple ways to detect support for a type trait __X in the compiler, depending on the oldest version of Clang you wish to support.
* From Clang 10 onwards, __has_builtin(__X) can be used.
* From Clang 6 onwards, !__is_identifier(__X) can be used.
* From Clang 3 onwards, __has_feature(X) can be used, but only supports the following traits:

@ZERICO2005 ZERICO2005 marked this pull request as ready for review March 22, 2025 03:34
@adriweb adriweb merged commit 3e58221 into master Mar 22, 2025
9 checks passed
@adriweb adriweb deleted the pr/expand_type_traits branch March 22, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants