-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[libc++] Implement the <type_traits>
parts of P1317R2
#151480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
frederick-vs-ja
wants to merge
7
commits into
llvm:main
Choose a base branch
from
frederick-vs-ja:p1317r2-type-traits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,126
−68
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6cf03e7
[libc++] Implement the `<type_traits>` parts of P1317R2
frederick-vs-ja a700737
Address review comments (except for tests)
frederick-vs-ja 12604b6
Fix CMakeLists.txt
frederick-vs-ja b51bcad
Attempt to expand `std_core`
frederick-vs-ja f060361
Fix `utility_core`
frederick-vs-ja 9f3c5f6
Fix `functional_core`
frederick-vs-ja 6be0f48
Fix `iterator_operations`
frederick-vs-ja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,115 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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_APPLICABLE_H | ||
#define _LIBCPP___TYPE_TRAITS_IS_APPLICABLE_H | ||
|
||
#include <__config> | ||
#include <__cstddef/size_t.h> | ||
#include <__fwd/get.h> | ||
#include <__tuple/tuple_like.h> | ||
#include <__tuple/tuple_size.h> | ||
#include <__type_traits/conjunction.h> | ||
#include <__type_traits/integral_constant.h> | ||
#include <__type_traits/invoke.h> | ||
#include <__type_traits/remove_reference.h> | ||
#include <__utility/declval.h> | ||
#include <__utility/integer_sequence.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 26 | ||
|
||
template <class _Fn, class _Tuple> | ||
struct __apply_result_disabled_base {}; | ||
|
||
template <class _Fn, class _Tuple, class _Tp> | ||
struct __apply_result_enabled_base { | ||
using type _LIBCPP_NODEBUG = _Tp; | ||
}; | ||
|
||
template <bool _Applicable, bool _Nothrow, class _Tp> | ||
struct __applicability_traits { | ||
static constexpr bool __applicable = true; | ||
static constexpr bool __nothrow_applicable = _Nothrow; | ||
|
||
template <class _Fn, class _Tuple> | ||
using __base_type _LIBCPP_NODEBUG = __apply_result_enabled_base<_Fn, _Tuple, _Tp>; | ||
}; | ||
|
||
template <bool _Nothrow, class _Tp> | ||
struct __applicability_traits<false, _Nothrow, _Tp> { | ||
static_assert(!_Nothrow, "misspecified [_Applicable = false, _Nothrow = true]"); | ||
static constexpr bool __applicable = false; | ||
static constexpr bool __nothrow_applicable = false; | ||
|
||
template <class _Fn, class _Tuple> | ||
using __base_type _LIBCPP_NODEBUG = __apply_result_disabled_base<_Fn, _Tuple>; | ||
}; | ||
|
||
template <class _Fn, class _Tuple, size_t... _Is> | ||
concept __tuple_applicable_impl = requires(_Tuple&& __tuple) { | ||
[](auto&&...) {}(std::get<_Is>(static_cast<_Tuple &&>(__tuple))...); | ||
} && __is_invocable_v<_Fn, decltype(std::get<_Is>(std::declval<_Tuple>()))...>; | ||
|
||
template <class _Fn, class _Tuple, size_t... _Is> | ||
concept __tuple_nothrow_applicable_impl = requires(_Tuple&& __tuple) { | ||
{ | ||
[](auto&&...) noexcept {}(std::get<_Is>(static_cast<_Tuple &&>(__tuple))...) | ||
} noexcept; | ||
} && __is_nothrow_invocable_v<_Fn, decltype(std::get<_Is>(std::declval<_Tuple>()))...>; | ||
|
||
template <class _Fn, class _Tuple> | ||
consteval auto __applicability_traits_of() { | ||
if constexpr (__tuple_like<_Tuple>) | ||
return []<size_t... _Is>(index_sequence<_Is...>) { | ||
if constexpr (__tuple_applicable_impl<_Fn, _Tuple, _Is...>) { | ||
return __applicability_traits< | ||
true, | ||
__tuple_nothrow_applicable_impl<_Fn, _Tuple, _Is...>, | ||
// FIXME: Use __invoke_result_y after merging https://github.com/llvm/llvm-project/pull/151028. | ||
typename __invoke_result<_Fn, decltype(std::get<_Is>(std::declval<_Tuple>()))...>::type>{}; | ||
} else | ||
return __applicability_traits<false, false, void>{}; | ||
}(make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>{}); | ||
else | ||
return __applicability_traits<false, false, void>{}; | ||
} | ||
|
||
template <class _Fn, class _Tuple> | ||
struct _LIBCPP_NO_SPECIALIZATIONS is_applicable | ||
: bool_constant<decltype(std::__applicability_traits_of<_Fn, _Tuple>())::__applicable> {}; | ||
|
||
template <class _Fn, class _Tuple> | ||
struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_applicable | ||
: bool_constant<decltype(std::__applicability_traits_of<_Fn, _Tuple>())::__nothrow_applicable> {}; | ||
|
||
template <class _Fn, class _Tuple> | ||
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_applicable_v = | ||
decltype(std::__applicability_traits_of<_Fn, _Tuple>())::__applicable; | ||
|
||
template <class _Fn, class _Tuple> | ||
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_applicable_v = | ||
decltype(std::__applicability_traits_of<_Fn, _Tuple>())::__nothrow_applicable; | ||
|
||
template <class _Fn, class _Tuple> | ||
struct _LIBCPP_NO_SPECIALIZATIONS apply_result | ||
: decltype(std::__applicability_traits_of<_Fn, _Tuple>())::template __base_type<_Fn, _Tuple> {}; | ||
|
||
template <class _Fn, class _Tuple> | ||
using apply_result_t = apply_result<_Fn, _Tuple>::type; | ||
|
||
#endif // _LIBCPP_STD_VER >= 26 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_IS_APPLICABLE_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These includes seemingly heavily break module builds. I guess we need to expand the
std_core
module a lot.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bit problematic. I almost wonder if we should put this new stuff under
__tuple
instead? It clearly belongs totype_traits
, but putting it inside__tuple
would simplify things from a modularization perspective.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving to
__tuple
and thetuple
clang module didn't work as we seemingly need to build<type_traits>
as a whole intostd_core
...