Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:54

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___ITERATOR_SIZE_H
0011 #define _LIBCPP___ITERATOR_SIZE_H
0012 
0013 #include <__config>
0014 #include <__cstddef/ptrdiff_t.h>
0015 #include <__cstddef/size_t.h>
0016 #include <__type_traits/common_type.h>
0017 #include <__type_traits/make_signed.h>
0018 
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 #  pragma GCC system_header
0021 #endif
0022 
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024 
0025 #if _LIBCPP_STD_VER >= 17
0026 
0027 template <class _Cont>
0028 _LIBCPP_HIDE_FROM_ABI constexpr auto size(const _Cont& __c) noexcept(noexcept(__c.size())) -> decltype(__c.size()) {
0029   return __c.size();
0030 }
0031 
0032 template <class _Tp, size_t _Sz>
0033 _LIBCPP_HIDE_FROM_ABI constexpr size_t size(const _Tp (&)[_Sz]) noexcept {
0034   return _Sz;
0035 }
0036 
0037 #  if _LIBCPP_STD_VER >= 20
0038 template <class _Cont>
0039 _LIBCPP_HIDE_FROM_ABI constexpr auto
0040 ssize(const _Cont& __c) noexcept(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(
0041     __c.size()))) -> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> {
0042   return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size());
0043 }
0044 
0045 // GCC complains about the implicit conversion from ptrdiff_t to size_t in
0046 // the array bound.
0047 _LIBCPP_DIAGNOSTIC_PUSH
0048 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wsign-conversion")
0049 template <class _Tp, ptrdiff_t _Sz>
0050 _LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept {
0051   return _Sz;
0052 }
0053 _LIBCPP_DIAGNOSTIC_POP
0054 #  endif
0055 
0056 #endif // _LIBCPP_STD_VER >= 17
0057 
0058 _LIBCPP_END_NAMESPACE_STD
0059 
0060 #endif // _LIBCPP___ITERATOR_SIZE_H