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_EXTENT_H
10 #define _LIBCPP___TYPE_TRAITS_EXTENT_H
11 
12 #include <__config>
13 #include <__type_traits/integral_constant.h>
14 #include <cstddef>
15 
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 #  pragma GCC system_header
18 #endif
19 
20 _LIBCPP_BEGIN_NAMESPACE_STD
21 
22 #if __has_builtin(__array_extent)
23 
24 template <class _Tp, size_t _Dim = 0>
25 struct _LIBCPP_TEMPLATE_VIS extent : integral_constant<size_t, __array_extent(_Tp, _Dim)> {};
26 
27 #  if _LIBCPP_STD_VER >= 17
28 template <class _Tp, unsigned _Ip = 0>
29 inline constexpr size_t extent_v = __array_extent(_Tp, _Ip);
30 #  endif
31 
32 #else // __has_builtin(__array_extent)
33 
34 template <class _Tp, unsigned _Ip = 0>
35 struct _LIBCPP_TEMPLATE_VIS extent : public integral_constant<size_t, 0> {};
36 template <class _Tp>
37 struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0> : public integral_constant<size_t, 0> {};
38 template <class _Tp, unsigned _Ip>
39 struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip - 1>::value> {};
40 template <class _Tp, size_t _Np>
41 struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0> : public integral_constant<size_t, _Np> {};
42 template <class _Tp, size_t _Np, unsigned _Ip>
43 struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip> : public integral_constant<size_t, extent<_Tp, _Ip - 1>::value> {};
44 
45 #  if _LIBCPP_STD_VER >= 17
46 template <class _Tp, unsigned _Ip = 0>
47 inline constexpr size_t extent_v = extent<_Tp, _Ip>::value;
48 #  endif
49 
50 #endif // __has_builtin(__array_extent)
51 
52 _LIBCPP_END_NAMESPACE_STD
53 
54 #endif // _LIBCPP___TYPE_TRAITS_EXTENT_H
55