* [committed] libstdc++: Add std::__conditional_t alias template
@ 2021-10-01 19:42 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-10-01 19:42 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 3075 bytes --]
This change is inspired by the suggestion in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1715r0.html
The new std::__conditional_t alias template is functionally equivalent
to std::conditional_t but should be more efficient to compile, due to
only ever instantiating two specializations (std::__conditional<true>
and std::__conditional<false>) rather than a new specialization for
every use of std::conditional.
The new alias template is also available in C++11, unlike the C++14
std::conditional_t alias.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
* include/std/type_traits (__conditional): New class template
for internal uses of std::conditional.
(__conditional_t): New alias template to replace conditional_t.
(__and_, __or_, __result_of_memfun, __result_of_memobj): Use
__conditional_t instead of conditional::type.
* include/bits/atomic_base.h (__atomic_impl::_Diff): Likewise.
* include/bits/hashtable.h (_Hashtable): Likewise.
* include/bits/hashtable_policy.h (_Node_iterator, _Insert_base)
(_Local_iterator): Likewise. Replace typedefs with
using-declarations.
* include/bits/move.h (move_if_noexcept): Use __conditional_t.
* include/bits/parse_numbers.h (_Select_int_base): Likewise.
* include/bits/ptr_traits.h (__make_not_void): Likewise.
* include/bits/ranges_algobase.h (__copy_or_move_backward)
(__copy_or_move): Likewise.
* include/bits/ranges_base.h (borrowed_iterator_t): Likewise.
* include/bits/ranges_util.h (borrowed_subrange_t): Likewise.
* include/bits/regex_compiler.h (_BracketMatcher): Use
__conditional_t. Replace typedefs with using-declarations.
* include/bits/shared_ptr_base.h (__shared_count): Use
__conditional_t.
* include/bits/stl_algobase.h (__copy_move, __copy_move_backward):
Likewise.
* include/bits/stl_iterator.h (__detail::__clamp_iter_cat)
(reverse_iterator::iterator_concept)
(__make_move_if_noexcept_iterator)
(iterator_traits<common_iterator<_It, _Sent>>)
(iterator_traits<counted_iterator<_It>>): Likewise.
* include/bits/stl_pair.h (_PCC, pair::operator=): Likewise.
* include/bits/stl_tree.h (_Rb_tree::insert_return_type)
(_Rb_tree::_M_clone_node): Likewise.
* include/bits/unique_ptr.h (unique_ptr(unique_ptr<U,E>&&)):
Likewise.
* include/bits/uses_allocator.h (__uses_alloc): Likewise.
(__is_uses_allocator_predicate): Likewise.
* include/debug/functions.h (__foreign_iterator_aux2): Likewise.
* include/experimental/any (any::_Manager, __any_caster):
Likewise.
* include/experimental/executor (async_completion): Likewise.
* include/experimental/functional (__boyer_moore_base_t):
Likewise.
* include/std/any (any::_Manager): Likewise.
* include/std/functional (__boyer_moore_base_t): Likewise.
* include/std/ranges (borrowed_iterator_t)
(borrowed_subrange_t, __detail::__maybe_present_t)
(__detail::__maybe_const_t, split_view): Likewise.
* include/std/tuple (__empty_not_final, tuple::operator=):
Likewise.
* include/std/variant (__detail::__variant::__get_t): Likewise.
Tested powerpc64le-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 39300 bytes --]
commit a09bb4a852f82af02b3f965358cd44b0aa266a5b
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu May 6 16:26:21 2021
libstdc++: Add std::__conditional_t alias template
This change is inspired by the suggestion in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1715r0.html
The new std::__conditional_t alias template is functionally equivalent
to std::conditional_t but should be more efficient to compile, due to
only ever instantiating two specializations (std::__conditional<true>
and std::__conditional<false>) rather than a new specialization for
every use of std::conditional.
The new alias template is also available in C++11, unlike the C++14
std::conditional_t alias.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
* include/std/type_traits (__conditional): New class template
for internal uses of std::conditional.
(__conditional_t): New alias template to replace conditional_t.
(__and_, __or_, __result_of_memfun, __result_of_memobj): Use
__conditional_t instead of conditional::type.
* include/bits/atomic_base.h (__atomic_impl::_Diff): Likewise.
* include/bits/hashtable.h (_Hashtable): Likewise.
* include/bits/hashtable_policy.h (_Node_iterator, _Insert_base)
(_Local_iterator): Likewise. Replace typedefs with
using-declarations.
* include/bits/move.h (move_if_noexcept): Use __conditional_t.
* include/bits/parse_numbers.h (_Select_int_base): Likewise.
* include/bits/ptr_traits.h (__make_not_void): Likewise.
* include/bits/ranges_algobase.h (__copy_or_move_backward)
(__copy_or_move): Likewise.
* include/bits/ranges_base.h (borrowed_iterator_t): Likewise.
* include/bits/ranges_util.h (borrowed_subrange_t): Likewise.
* include/bits/regex_compiler.h (_BracketMatcher): Use
__conditional_t. Replace typedefs with using-declarations.
* include/bits/shared_ptr_base.h (__shared_count): Use
__conditional_t.
* include/bits/stl_algobase.h (__copy_move, __copy_move_backward):
Likewise.
* include/bits/stl_iterator.h (__detail::__clamp_iter_cat)
(reverse_iterator::iterator_concept)
(__make_move_if_noexcept_iterator)
(iterator_traits<common_iterator<_It, _Sent>>)
(iterator_traits<counted_iterator<_It>>): Likewise.
* include/bits/stl_pair.h (_PCC, pair::operator=): Likewise.
* include/bits/stl_tree.h (_Rb_tree::insert_return_type)
(_Rb_tree::_M_clone_node): Likewise.
* include/bits/unique_ptr.h (unique_ptr(unique_ptr<U,E>&&)):
Likewise.
* include/bits/uses_allocator.h (__uses_alloc): Likewise.
(__is_uses_allocator_predicate): Likewise.
* include/debug/functions.h (__foreign_iterator_aux2): Likewise.
* include/experimental/any (any::_Manager, __any_caster):
Likewise.
* include/experimental/executor (async_completion): Likewise.
* include/experimental/functional (__boyer_moore_base_t):
Likewise.
* include/std/any (any::_Manager): Likewise.
* include/std/functional (__boyer_moore_base_t): Likewise.
* include/std/ranges (borrowed_iterator_t)
(borrowed_subrange_t, __detail::__maybe_present_t)
(__detail::__maybe_const_t, split_view): Likewise.
* include/std/tuple (__empty_not_final, tuple::operator=):
Likewise.
* include/std/variant (__detail::__variant::__get_t): Likewise.
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 71e1de078b5..9e18aadadaf 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -946,7 +946,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// As above, but for difference_type arguments.
template<typename _Tp>
- using _Diff = conditional_t<is_pointer_v<_Tp>, ptrdiff_t, _Val<_Tp>>;
+ using _Diff = __conditional_t<is_pointer_v<_Tp>, ptrdiff_t, _Val<_Tp>>;
template<size_t _Size, size_t _Align>
_GLIBCXX_ALWAYS_INLINE bool
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index 92516b81ae5..79a3096b62b 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -317,8 +317,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Ht>
static constexpr
- typename conditional<std::is_lvalue_reference<_Ht>::value,
- const value_type&, value_type&&>::type
+ __conditional_t<std::is_lvalue_reference<_Ht>::value,
+ const value_type&, value_type&&>
__fwd_value_for(value_type& __val) noexcept
{ return std::move(__val); }
@@ -875,10 +875,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_insert_unique(_Kt&&, _Arg&&, const _NodeGenerator&);
template<typename _Kt>
- static typename conditional<
+ static __conditional_t<
__and_<__is_nothrow_invocable<_Hash&, const key_type&>,
__not_<__is_nothrow_invocable<_Hash&, _Kt>>>::value,
- key_type, _Kt&&>::type
+ key_type, _Kt&&>
_S_forward_key(_Kt&& __k)
{ return std::forward<_Kt>(__k); }
@@ -1540,9 +1540,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
__alloc_node_gen_t __alloc_gen(*this);
- using _Fwd_Ht = typename
- conditional<__move_if_noexcept_cond<value_type>::value,
- const _Hashtable&, _Hashtable&&>::type;
+ using _Fwd_Ht = __conditional_t<
+ __move_if_noexcept_cond<value_type>::value,
+ const _Hashtable&, _Hashtable&&>;
_M_assign(std::forward<_Fwd_Ht>(__ht), __alloc_gen);
__ht.clear();
}
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index 2130c958262..2f8502588f5 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -360,15 +360,15 @@ namespace __detail
using __node_type = typename __base_type::__node_type;
public:
- typedef _Value value_type;
- typedef std::ptrdiff_t difference_type;
- typedef std::forward_iterator_tag iterator_category;
+ using value_type = _Value;
+ using difference_type = std::ptrdiff_t;
+ using iterator_category = std::forward_iterator_tag;
- using pointer = typename std::conditional<__constant_iterators,
- const value_type*, value_type*>::type;
+ using pointer = __conditional_t<__constant_iterators,
+ const value_type*, value_type*>;
- using reference = typename std::conditional<__constant_iterators,
- const value_type&, value_type&>::type;
+ using reference = __conditional_t<__constant_iterators,
+ const value_type&, value_type&>;
_Node_iterator() = default;
@@ -867,12 +867,13 @@ namespace __detail
using iterator = _Node_iterator<_Value, __constant_iterators::value,
__hash_cached::value>;
- using const_iterator = _Node_const_iterator<_Value, __constant_iterators::value,
+ using const_iterator = _Node_const_iterator<_Value,
+ __constant_iterators::value,
__hash_cached::value>;
- using __ireturn_type = typename std::conditional<__unique_keys::value,
- std::pair<iterator, bool>,
- iterator>::type;
+ using __ireturn_type = __conditional_t<__unique_keys::value,
+ std::pair<iterator, bool>,
+ iterator>;
__ireturn_type
insert(const value_type& __v)
@@ -1482,15 +1483,13 @@ namespace __detail
using __hash_code_base = typename __base_type::__hash_code_base;
public:
- typedef _Value value_type;
- typedef typename std::conditional<__constant_iterators,
- const value_type*, value_type*>::type
- pointer;
- typedef typename std::conditional<__constant_iterators,
- const value_type&, value_type&>::type
- reference;
- typedef std::ptrdiff_t difference_type;
- typedef std::forward_iterator_tag iterator_category;
+ using value_type = _Value;
+ using pointer = __conditional_t<__constant_iterators,
+ const value_type*, value_type*>;
+ using reference = __conditional_t<__constant_iterators,
+ const value_type&, value_type&>;
+ using difference_type = ptrdiff_t;
+ using iterator_category = forward_iterator_tag;
_Local_iterator() = default;
diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h
index 2dd7ed9e4f9..1c13abc4da8 100644
--- a/libstdc++-v3/include/bits/move.h
+++ b/libstdc++-v3/include/bits/move.h
@@ -120,8 +120,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/
template<typename _Tp>
_GLIBCXX_NODISCARD
- constexpr typename
- conditional<__move_if_noexcept_cond<_Tp>::value, const _Tp&, _Tp&&>::type
+ constexpr
+ __conditional_t<__move_if_noexcept_cond<_Tp>::value, const _Tp&, _Tp&&>
move_if_noexcept(_Tp& __x) noexcept
{ return std::move(__x); }
diff --git a/libstdc++-v3/include/bits/parse_numbers.h b/libstdc++-v3/include/bits/parse_numbers.h
index 56186612f0f..54b63c0e2bb 100644
--- a/libstdc++-v3/include/bits/parse_numbers.h
+++ b/libstdc++-v3/include/bits/parse_numbers.h
@@ -266,9 +266,9 @@ namespace __select_int
template<unsigned long long _Val, typename _IntType, typename... _Ints>
struct _Select_int_base<_Val, _IntType, _Ints...>
- : conditional_t<(_Val <= __gnu_cxx::__int_traits<_IntType>::__max),
- integral_constant<_IntType, (_IntType)_Val>,
- _Select_int_base<_Val, _Ints...>>
+ : __conditional_t<(_Val <= __gnu_cxx::__int_traits<_IntType>::__max),
+ integral_constant<_IntType, (_IntType)_Val>,
+ _Select_int_base<_Val, _Ints...>>
{ };
template<unsigned long long _Val>
diff --git a/libstdc++-v3/include/bits/ptr_traits.h b/libstdc++-v3/include/bits/ptr_traits.h
index 653a3580117..115b86d43e4 100644
--- a/libstdc++-v3/include/bits/ptr_traits.h
+++ b/libstdc++-v3/include/bits/ptr_traits.h
@@ -73,7 +73,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
using __make_not_void
- = typename conditional<is_void<_Tp>::value, __undefined, _Tp>::type;
+ = __conditional_t<is_void<_Tp>::value, __undefined, _Tp>;
/**
* @brief Uniform interface to all pointer-like types
diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h
index 78c295981d5..cfbac839749 100644
--- a/libstdc++-v3/include/bits/ranges_algobase.h
+++ b/libstdc++-v3/include/bits/ranges_algobase.h
@@ -195,9 +195,9 @@ namespace ranges
requires (_IsMove
? indirectly_movable<_Iter, _Out>
: indirectly_copyable<_Iter, _Out>)
- constexpr conditional_t<_IsMove,
- move_backward_result<_Iter, _Out>,
- copy_backward_result<_Iter, _Out>>
+ constexpr __conditional_t<_IsMove,
+ move_backward_result<_Iter, _Out>,
+ copy_backward_result<_Iter, _Out>>
__copy_or_move_backward(_Iter __first, _Sent __last, _Out __result);
template<bool _IsMove,
@@ -206,9 +206,9 @@ namespace ranges
requires (_IsMove
? indirectly_movable<_Iter, _Out>
: indirectly_copyable<_Iter, _Out>)
- constexpr conditional_t<_IsMove,
- move_result<_Iter, _Out>,
- copy_result<_Iter, _Out>>
+ constexpr __conditional_t<_IsMove,
+ move_result<_Iter, _Out>,
+ copy_result<_Iter, _Out>>
__copy_or_move(_Iter __first, _Sent __last, _Out __result)
{
// TODO: implement more specializations to be at least on par with
@@ -349,9 +349,9 @@ namespace ranges
requires (_IsMove
? indirectly_movable<_Iter, _Out>
: indirectly_copyable<_Iter, _Out>)
- constexpr conditional_t<_IsMove,
- move_backward_result<_Iter, _Out>,
- copy_backward_result<_Iter, _Out>>
+ constexpr __conditional_t<_IsMove,
+ move_backward_result<_Iter, _Out>,
+ copy_backward_result<_Iter, _Out>>
__copy_or_move_backward(_Iter __first, _Sent __last, _Out __result)
{
// TODO: implement more specializations to be at least on par with
diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h
index 49c7d9c9f06..d6166ab1dd3 100644
--- a/libstdc++-v3/include/bits/ranges_base.h
+++ b/libstdc++-v3/include/bits/ranges_base.h
@@ -907,9 +907,9 @@ namespace ranges
};
template<range _Range>
- using borrowed_iterator_t = conditional_t<borrowed_range<_Range>,
- iterator_t<_Range>,
- dangling>;
+ using borrowed_iterator_t = __conditional_t<borrowed_range<_Range>,
+ iterator_t<_Range>,
+ dangling>;
} // namespace ranges
_GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/bits/ranges_util.h b/libstdc++-v3/include/bits/ranges_util.h
index 4e87cfc6ef1..7e7b958d274 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -418,9 +418,9 @@ namespace ranges
enable_borrowed_range<subrange<_It, _Sent, _Kind>> = true;
template<range _Range>
- using borrowed_subrange_t = conditional_t<borrowed_range<_Range>,
- subrange<iterator_t<_Range>>,
- dangling>;
+ using borrowed_subrange_t = __conditional_t<borrowed_range<_Range>,
+ subrange<iterator_t<_Range>>,
+ dangling>;
} // namespace ranges
// The following ranges algorithms are used by <ranges>, and are defined here
diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h
index 62a49bf52cf..88c60c2bed7 100644
--- a/libstdc++-v3/include/bits/regex_compiler.h
+++ b/libstdc++-v3/include/bits/regex_compiler.h
@@ -485,17 +485,17 @@ namespace __detail
private:
// Currently we only use the cache for char
- typedef typename std::is_same<_CharT, char>::type _UseCache;
+ using _UseCache = typename std::is_same<_CharT, char>::type;
static constexpr size_t
_S_cache_size =
1ul << (sizeof(_CharT) * __CHAR_BIT__ * int(_UseCache::value));
struct _Dummy { };
- typedef typename std::conditional<_UseCache::value,
- std::bitset<_S_cache_size>,
- _Dummy>::type _CacheT;
- typedef typename std::make_unsigned<_CharT>::type _UnsignedCharT;
+ using _CacheT = std::__conditional_t<_UseCache::value,
+ std::bitset<_S_cache_size>,
+ _Dummy>;
+ using _UnsignedCharT = typename std::make_unsigned<_CharT>::type;
bool
_M_apply(_CharT __ch, false_type) const;
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h
index 5be935d174d..3473a74280d 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -675,9 +675,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return;
using _Ptr = typename unique_ptr<_Tp, _Del>::pointer;
- using _Del2 = typename conditional<is_reference<_Del>::value,
+ using _Del2 = __conditional_t<is_reference<_Del>::value,
reference_wrapper<typename remove_reference<_Del>::type>,
- _Del>::type;
+ _Del>;
using _Sp_cd_type
= _Sp_counted_deleter<_Ptr, _Del2, allocator<void>, _Lp>;
using _Alloc = allocator<_Sp_cd_type>;
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index e1443b8a92a..8627d59b589 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -420,11 +420,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__copy_m(const _Tp* __first, const _Tp* __last, _Tp* __result)
{
#if __cplusplus >= 201103L
- using __assignable = conditional<_IsMove,
- is_move_assignable<_Tp>,
- is_copy_assignable<_Tp>>;
+ using __assignable = __conditional_t<_IsMove,
+ is_move_assignable<_Tp>,
+ is_copy_assignable<_Tp>>;
// trivial types can have deleted assignment
- static_assert( __assignable::type::value, "type must be assignable" );
+ static_assert( __assignable::value, "type must be assignable" );
#endif
const ptrdiff_t _Num = __last - __first;
if (_Num)
@@ -731,11 +731,11 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
__copy_move_b(const _Tp* __first, const _Tp* __last, _Tp* __result)
{
#if __cplusplus >= 201103L
- using __assignable = conditional<_IsMove,
- is_move_assignable<_Tp>,
- is_copy_assignable<_Tp>>;
+ using __assignable = __conditional_t<_IsMove,
+ is_move_assignable<_Tp>,
+ is_copy_assignable<_Tp>>;
// trivial types can have deleted assignment
- static_assert( __assignable::type::value, "type must be assignable" );
+ static_assert( __assignable::value, "type must be assignable" );
#endif
const ptrdiff_t _Num = __last - __first;
if (_Num)
diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index df774eeb63f..8afd6756613 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -100,7 +100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// otherwise use _Otherwise.
template<typename _Cat, typename _Limit, typename _Otherwise = _Cat>
using __clamp_iter_cat
- = conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
+ = __conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
}
#endif
@@ -155,9 +155,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef typename __traits_type::reference reference;
#else
using iterator_concept
- = conditional_t<random_access_iterator<_Iterator>,
- random_access_iterator_tag,
- bidirectional_iterator_tag>;
+ = __conditional_t<random_access_iterator<_Iterator>,
+ random_access_iterator_tag,
+ bidirectional_iterator_tag>;
using iterator_category
= __detail::__clamp_iter_cat<typename __traits_type::iterator_category,
random_access_iterator_tag>;
@@ -1455,9 +1455,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef _Iterator pointer;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2106. move_iterator wrapping iterators returning prvalues
- typedef typename conditional<is_reference<__base_ref>::value,
- typename remove_reference<__base_ref>::type&&,
- __base_ref>::type reference;
+ using reference
+ = __conditional_t<is_reference<__base_ref>::value,
+ typename remove_reference<__base_ref>::type&&,
+ __base_ref>;
#endif
_GLIBCXX17_CONSTEXPR
@@ -1762,9 +1763,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return move_iterator<_Iterator>(std::move(__i)); }
template<typename _Iterator, typename _ReturnType
- = typename conditional<__move_if_noexcept_cond
+ = __conditional_t<__move_if_noexcept_cond
<typename iterator_traits<_Iterator>::value_type>::value,
- _Iterator, move_iterator<_Iterator>>::type>
+ _Iterator, move_iterator<_Iterator>>>
inline _GLIBCXX17_CONSTEXPR _ReturnType
__make_move_if_noexcept_iterator(_Iterator __i)
{ return _ReturnType(__i); }
@@ -1772,8 +1773,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Overload for pointers that matches std::move_if_noexcept more closely,
// returning a constant iterator when we don't want to move.
template<typename _Tp, typename _ReturnType
- = typename conditional<__move_if_noexcept_cond<_Tp>::value,
- const _Tp*, move_iterator<_Tp*>>::type>
+ = __conditional_t<__move_if_noexcept_cond<_Tp>::value,
+ const _Tp*, move_iterator<_Tp*>>>
inline _GLIBCXX17_CONSTEXPR _ReturnType
__make_move_if_noexcept_iterator(_Tp* __i)
{ return _ReturnType(__i); }
@@ -2178,8 +2179,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
public:
- using iterator_concept = conditional_t<forward_iterator<_It>,
- forward_iterator_tag, input_iterator_tag>;
+ using iterator_concept = __conditional_t<forward_iterator<_It>,
+ forward_iterator_tag,
+ input_iterator_tag>;
using iterator_category = decltype(_S_iter_cat());
using value_type = iter_value_t<_It>;
using difference_type = iter_difference_t<_It>;
@@ -2459,9 +2461,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
requires same_as<__detail::__iter_traits<_It>, iterator_traits<_It>>
struct iterator_traits<counted_iterator<_It>> : iterator_traits<_It>
{
- using pointer = conditional_t<contiguous_iterator<_It>,
- add_pointer_t<iter_reference_t<_It>>,
- void>;
+ using pointer = __conditional_t<contiguous_iterator<_It>,
+ add_pointer_t<iter_reference_t<_It>>,
+ void>;
};
#endif // C++20
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index 329485ce3b2..5b400daf97f 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -129,15 +129,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
is_convertible<_U2&&, _T2>>::value;
}
-
template <bool __implicit, typename _U1, typename _U2>
static constexpr bool _DeprConsPair()
{
using __do_converts = __and_<is_convertible<_U1&&, _T1>,
is_convertible<_U2&&, _T2>>;
- using __converts = typename conditional<__implicit,
- __do_converts,
- __not_<__do_converts>>::type;
+ using __converts = __conditional_t<__implicit,
+ __do_converts,
+ __not_<__do_converts>>;
return __and_<is_constructible<_T1, _U1&&>,
is_constructible<_T2, _U2&&>,
__converts
@@ -561,10 +560,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
second(std::forward<_U2>(__p.second)) { }
pair&
- operator=(typename conditional<
- __and_<is_copy_assignable<_T1>,
- is_copy_assignable<_T2>>::value,
- const pair&, const __nonesuch&>::type __p)
+ operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
+ is_copy_assignable<_T2>>::value,
+ const pair&, const __nonesuch&> __p)
{
first = __p.first;
second = __p.second;
@@ -572,10 +570,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
pair&
- operator=(typename conditional<
- __and_<is_move_assignable<_T1>,
- is_move_assignable<_T2>>::value,
- pair&&, __nonesuch&&>::type __p)
+ operator=(__conditional_t<__and_<is_move_assignable<_T1>,
+ is_move_assignable<_T2>>::value,
+ pair&&, __nonesuch&&> __p)
noexcept(__and_<is_nothrow_move_assignable<_T1>,
is_nothrow_move_assignable<_T2>>::value)
{
diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index e4e3e0b985c..0692525be57 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -637,9 +637,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_clone_node(_Link_type __x, _NodeGen& __node_gen)
{
#if __cplusplus >= 201103L
- using _Vp = typename conditional<_MoveValue,
- value_type&&,
- const value_type&>::type;
+ using _Vp = __conditional_t<_MoveValue,
+ value_type&&,
+ const value_type&>;
#endif
_Link_type __tmp
= __node_gen(_GLIBCXX_FORWARD(_Vp, *__x->_M_valptr()));
@@ -821,7 +821,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus > 201402L
using node_type = _Node_handle<_Key, _Val, _Node_allocator>;
using insert_return_type = _Node_insert_return<
- conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
+ __conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>,
node_type>;
#endif
diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h
index da582176e84..c257e9573e0 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -338,9 +338,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/
template<typename _Up, typename _Ep, typename = _Require<
__safe_conversion_up<_Up, _Ep>,
- typename conditional<is_reference<_Dp>::value,
- is_same<_Ep, _Dp>,
- is_convertible<_Ep, _Dp>>::type>>
+ __conditional_t<is_reference<_Dp>::value,
+ is_same<_Ep, _Dp>,
+ is_convertible<_Ep, _Dp>>>>
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
: _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
{ }
@@ -605,9 +605,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Up, typename _Ep, typename = _Require<
__safe_conversion_up<_Up, _Ep>,
- typename conditional<is_reference<_Dp>::value,
- is_same<_Ep, _Dp>,
- is_convertible<_Ep, _Dp>>::type>>
+ __conditional_t<is_reference<_Dp>::value,
+ is_same<_Ep, _Dp>,
+ is_convertible<_Ep, _Dp>>>>
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
: _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
{ }
diff --git a/libstdc++-v3/include/bits/uses_allocator.h b/libstdc++-v3/include/bits/uses_allocator.h
index 36b219ccc59..358c5713da5 100644
--- a/libstdc++-v3/include/bits/uses_allocator.h
+++ b/libstdc++-v3/include/bits/uses_allocator.h
@@ -86,10 +86,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, typename _Alloc, typename... _Args>
struct __uses_alloc<true, _Tp, _Alloc, _Args...>
- : conditional<
+ : __conditional_t<
is_constructible<_Tp, allocator_arg_t, const _Alloc&, _Args...>::value,
__uses_alloc1<_Alloc>,
- __uses_alloc2<_Alloc>>::type
+ __uses_alloc2<_Alloc>>
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2586. Wrong value category used in scoped_allocator_adaptor::construct
@@ -131,10 +131,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<template<typename...> class _Predicate,
typename _Tp, typename _Alloc, typename... _Args>
struct __is_uses_allocator_predicate
- : conditional<uses_allocator<_Tp, _Alloc>::value,
+ : __conditional_t<uses_allocator<_Tp, _Alloc>::value,
__or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
_Predicate<_Tp, _Args..., _Alloc>>,
- _Predicate<_Tp, _Args...>>::type { };
+ _Predicate<_Tp, _Args...>> { };
template<typename _Tp, typename _Alloc, typename... _Args>
struct __is_uses_allocator_constructible
diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h
index 6cac11f2abd..5d5354410f3 100644
--- a/libstdc++-v3/include/debug/functions.h
+++ b/libstdc++-v3/include/debug/functions.h
@@ -33,7 +33,7 @@
#if __cplusplus >= 201103L
# include <bits/stl_iterator.h> // for __miter_base
-# include <type_traits> // for is_lvalue_reference and conditional.
+# include <type_traits> // for is_lvalue_reference and __conditional_t.
#endif
#include <debug/helper_functions.h>
@@ -158,8 +158,8 @@ namespace __gnu_debug
using __lvalref = std::is_lvalue_reference<
typename std::iterator_traits<_InputIterator>::reference>;
using __contiguous = _Is_contiguous_sequence<_Sequence>;
- using __tag = typename std::conditional<__lvalref::value, __contiguous,
- std::__false_type>::type;
+ using __tag = std::__conditional_t<__lvalref::value, __contiguous,
+ std::__false_type>;
#endif
return __foreign_iterator_aux3(__it, __other, __other_end, __tag());
}
diff --git a/libstdc++-v3/include/experimental/any b/libstdc++-v3/include/experimental/any
index 7d18f267e8b..44f5db0fb87 100644
--- a/libstdc++-v3/include/experimental/any
+++ b/libstdc++-v3/include/experimental/any
@@ -115,9 +115,9 @@ inline namespace fundamentals_v1
struct _Manager_external; // creates contained object on the heap
template<typename _Tp>
- using _Manager = conditional_t<_Internal<_Tp>::value,
- _Manager_internal<_Tp>,
- _Manager_external<_Tp>>;
+ using _Manager = __conditional_t<_Internal<_Tp>::value,
+ _Manager_internal<_Tp>,
+ _Manager_external<_Tp>>;
template<typename _Tp, typename _Decayed = decay_t<_Tp>>
using _Decay = enable_if_t<!is_same<_Decayed, any>::value, _Decayed>;
@@ -430,8 +430,8 @@ inline namespace fundamentals_v1
// If the type _Tp could never be stored in an any we don't want to
// instantiate _Manager<_Tp>, so use _Manager<any::_Op> instead, which
// is explicitly specialized and has a no-op _S_manage function.
- using _Vp = conditional_t<__and_<__does_not_decay, __is_copyable>::value,
- _Up, any::_Op>;
+ using _Vp = __conditional_t<__and_<__does_not_decay, __is_copyable>{},
+ _Up, any::_Op>;
// First try comparing function addresses, which works without RTTI
if (__any->_M_manager == &any::_Manager<_Vp>::_S_manage
#if __cpp_rtti
diff --git a/libstdc++-v3/include/experimental/executor b/libstdc++-v3/include/experimental/executor
index 4322a7f5caf..e7a0c6e6d98 100644
--- a/libstdc++-v3/include/experimental/executor
+++ b/libstdc++-v3/include/experimental/executor
@@ -389,7 +389,7 @@ inline namespace v1
= typename __result_type::completion_handler_type;
private:
- using __handler_type = conditional_t<
+ using __handler_type = __conditional_t<
is_same<_CompletionToken, completion_handler_type>::value,
completion_handler_type&,
completion_handler_type>;
diff --git a/libstdc++-v3/include/experimental/functional b/libstdc++-v3/include/experimental/functional
index 0a2b9381d70..8be2fab1e31 100644
--- a/libstdc++-v3/include/experimental/functional
+++ b/libstdc++-v3/include/experimental/functional
@@ -164,9 +164,9 @@ inline namespace fundamentals_v1
typename _Val = typename iterator_traits<_RAIter>::value_type,
typename _Diff = typename iterator_traits<_RAIter>::difference_type>
using __boyer_moore_base_t
- = std::conditional_t<std::__is_byte_like<_Val, _Pred>::value,
- __boyer_moore_array_base<_Diff, 256, _Pred>,
- __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
+ = std::__conditional_t<std::__is_byte_like<_Val, _Pred>::value,
+ __boyer_moore_array_base<_Diff, 256, _Pred>,
+ __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
template<typename _RAIter, typename _Hash
= std::hash<typename std::iterator_traits<_RAIter>::value_type>,
diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
index 1fce95730ea..625cac619f0 100644
--- a/libstdc++-v3/include/std/any
+++ b/libstdc++-v3/include/std/any
@@ -102,9 +102,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct _Manager_external; // creates contained object on the heap
template<typename _Tp>
- using _Manager = conditional_t<_Internal<_Tp>::value,
- _Manager_internal<_Tp>,
- _Manager_external<_Tp>>;
+ using _Manager = __conditional_t<_Internal<_Tp>::value,
+ _Manager_internal<_Tp>,
+ _Manager_external<_Tp>>;
template<typename _Tp, typename _VTp = decay_t<_Tp>>
using _Decay_if_not_any = enable_if_t<!is_same_v<_VTp, any>, _VTp>;
diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index 0b257926fd5..a13f67e4c7c 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -1117,9 +1117,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typename _Val = typename iterator_traits<_RAIter>::value_type,
typename _Diff = typename iterator_traits<_RAIter>::difference_type>
using __boyer_moore_base_t
- = conditional_t<__is_byte_like<_Val, _Pred>::value,
- __boyer_moore_array_base<_Diff, 256, _Pred>,
- __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
+ = __conditional_t<__is_byte_like<_Val, _Pred>::value,
+ __boyer_moore_array_base<_Diff, 256, _Pred>,
+ __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
template<typename _RAIter, typename _Hash
= hash<typename iterator_traits<_RAIter>::value_type>,
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index b373e4f05c0..07eae0cf94b 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -770,11 +770,11 @@ namespace __detail
// Data members using this alias should use [[no_unique_address]] so that
// they take no space when not needed.
template<bool _Present, typename _Tp>
- using __maybe_present_t = conditional_t<_Present, _Tp, _Empty>;
+ using __maybe_present_t = __conditional_t<_Present, _Tp, _Empty>;
// Alias for a type that is conditionally const.
template<bool _Const, typename _Tp>
- using __maybe_const_t = conditional_t<_Const, const _Tp, _Tp>;
+ using __maybe_const_t = __conditional_t<_Const, const _Tp, _Tp>;
} // namespace __detail
@@ -2920,9 +2920,9 @@ namespace views::__adaptor
bool _M_trailing_empty = false;
public:
- using iterator_concept = conditional_t<forward_range<_Base>,
- forward_iterator_tag,
- input_iterator_tag>;
+ using iterator_concept = __conditional_t<forward_range<_Base>,
+ forward_iterator_tag,
+ input_iterator_tag>;
// iterator_category defined in __lazy_split_view_outer_iter_cat
using difference_type = range_difference_t<_Base>;
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 120c80a2b78..94a4f0afd31 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -66,8 +66,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Use the Empty Base-class Optimization for empty, non-final types.
template<typename _Tp>
using __empty_not_final
- = typename conditional<__is_final(_Tp), false_type,
- __is_empty_non_tuple<_Tp>>::type;
+ = __conditional_t<__is_final(_Tp), false_type,
+ __is_empty_non_tuple<_Tp>>;
template<size_t _Idx, typename _Head,
bool = __empty_not_final<_Head>::value>
@@ -905,9 +905,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX20_CONSTEXPR
tuple&
- operator=(typename conditional<__assignable<const _Elements&...>(),
- const tuple&,
- const __nonesuch&>::type __in)
+ operator=(__conditional_t<__assignable<const _Elements&...>(),
+ const tuple&,
+ const __nonesuch&> __in)
noexcept(__nothrow_assignable<const _Elements&...>())
{
this->_M_assign(__in);
@@ -916,9 +916,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX20_CONSTEXPR
tuple&
- operator=(typename conditional<__assignable<_Elements...>(),
- tuple&&,
- __nonesuch&&>::type __in)
+ operator=(__conditional_t<__assignable<_Elements...>(),
+ tuple&&,
+ __nonesuch&&> __in)
noexcept(__nothrow_assignable<_Elements...>())
{
this->_M_assign(std::move(__in));
@@ -1274,9 +1274,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX20_CONSTEXPR
tuple&
- operator=(typename conditional<__assignable<const _T1&, const _T2&>(),
- const tuple&,
- const __nonesuch&>::type __in)
+ operator=(__conditional_t<__assignable<const _T1&, const _T2&>(),
+ const tuple&,
+ const __nonesuch&> __in)
noexcept(__nothrow_assignable<const _T1&, const _T2&>())
{
this->_M_assign(__in);
@@ -1285,9 +1285,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX20_CONSTEXPR
tuple&
- operator=(typename conditional<__assignable<_T1, _T2>(),
- tuple&&,
- __nonesuch&&>::type __in)
+ operator=(__conditional_t<__assignable<_T1, _T2>(),
+ tuple&&,
+ __nonesuch&&> __in)
noexcept(__nothrow_assignable<_T1, _T2>())
{
this->_M_assign(std::move(__in));
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index a0010d960b2..35ff5806c5d 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -100,8 +100,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Metaprogramming helper types.
- template<bool, typename, typename>
- struct conditional;
+ template<bool>
+ struct __conditional
+ {
+ template<typename _Tp, typename>
+ using type = _Tp;
+ };
+
+ template<>
+ struct __conditional<false>
+ {
+ template<typename, typename _Up>
+ using type = _Up;
+ };
+
+ // More efficient version of std::conditional_t for internal use (and C++11)
+ template<bool _Cond, typename _If, typename _Else>
+ using __conditional_t
+ = typename __conditional<_Cond>::template type<_If, _Else>;
/// @cond undocumented
template <typename _Type>
@@ -126,12 +142,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _B1, typename _B2>
struct __or_<_B1, _B2>
- : public conditional<_B1::value, _B1, _B2>::type
+ : public __conditional_t<_B1::value, _B1, _B2>
{ };
template<typename _B1, typename _B2, typename _B3, typename... _Bn>
struct __or_<_B1, _B2, _B3, _Bn...>
- : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
+ : public __conditional_t<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>
{ };
template<typename...>
@@ -149,12 +165,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _B1, typename _B2>
struct __and_<_B1, _B2>
- : public conditional<_B1::value, _B2, _B1>::type
+ : public __conditional_t<_B1::value, _B2, _B1>
{ };
template<typename _B1, typename _B2, typename _B3, typename... _Bn>
struct __and_<_B1, _B2, _B3, _Bn...>
- : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
+ : public __conditional_t<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>
{ };
template<typename _Pp>
@@ -2491,11 +2507,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef __remove_cvref_t<_Arg> _Argval;
typedef _Res _Class::* _MemPtr;
- typedef typename conditional<__or_<is_same<_Argval, _Class>,
+ typedef typename __conditional_t<__or_<is_same<_Argval, _Class>,
is_base_of<_Class, _Argval>>::value,
__result_of_memobj_ref<_MemPtr, _Arg>,
__result_of_memobj_deref<_MemPtr, _Arg>
- >::type::type type;
+ >::type type;
};
template<typename _MemPtr, typename _Arg, typename... _Args>
@@ -2506,10 +2522,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef typename remove_reference<_Arg>::type _Argval;
typedef _Res _Class::* _MemPtr;
- typedef typename conditional<is_base_of<_Class, _Argval>::value,
+ typedef typename __conditional_t<is_base_of<_Class, _Argval>::value,
__result_of_memfun_ref<_MemPtr, _Arg, _Args...>,
__result_of_memfun_deref<_MemPtr, _Arg, _Args...>
- >::type::type type;
+ >::type type;
};
// _GLIBCXX_RESOLVE_LIB_DEFECTS
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 19b2158690a..ddeefd9b35e 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1096,7 +1096,7 @@ namespace __variant
typename _AsV = decltype(__variant::__as(std::declval<_Variant>())),
typename _Tp = variant_alternative_t<_Np, remove_reference_t<_AsV>>>
using __get_t
- = conditional_t<is_lvalue_reference_v<_Variant>, _Tp&, _Tp&&>;
+ = __conditional_t<is_lvalue_reference_v<_Variant>, _Tp&, _Tp&&>;
// Return type of std::visit.
template<typename _Visitor, typename... _Variants>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-01 19:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 19:42 [committed] libstdc++: Add std::__conditional_t alias template Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).