@@ -1473,6 +1473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
/// rank
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
+ template<typename _Tp>
+ struct rank
+ : public integral_constant<std::size_t, __array_rank(_Tp)> { };
+#else
template<typename>
struct rank
: public integral_constant<std::size_t, 0> { };
@@ -1484,6 +1489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
struct rank<_Tp[]>
: public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
+#endif
/// extent
template<typename, unsigned _Uint = 0>
@@ -3583,12 +3589,17 @@ template <typename _Tp>
template <typename _Tp>
inline constexpr size_t alignment_of_v = alignment_of<_Tp>::value;
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__array_rank)
+template <typename _Tp>
+ inline constexpr size_t rank_v = __array_rank(_Tp);
+#else
template <typename _Tp>
inline constexpr size_t rank_v = 0;
template <typename _Tp, size_t _Size>
inline constexpr size_t rank_v<_Tp[_Size]> = 1 + rank_v<_Tp>;
template <typename _Tp>
inline constexpr size_t rank_v<_Tp[]> = 1 + rank_v<_Tp>;
+#endif
template <typename _Tp, unsigned _Idx = 0>
inline constexpr size_t extent_v = 0;
This patch optimizes the compilation performance of std::rank by dispatching to the new __array_rank built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (rank): Use __array_rank built-in trait. (rank_v): Likewise. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org> --- libstdc++-v3/include/std/type_traits | 11 +++++++++++ 1 file changed, 11 insertions(+)