Back to home page

EIC code displayed by LXR

 
 

    


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

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___CXX03___ITERATOR_SIZE_H
0011 #define _LIBCPP___CXX03___ITERATOR_SIZE_H
0012 
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__type_traits/common_type.h>
0015 #include <__cxx03/__type_traits/make_signed.h>
0016 #include <__cxx03/cstddef>
0017 
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 #  pragma GCC system_header
0020 #endif
0021 
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023 
0024 #if _LIBCPP_STD_VER >= 17
0025 
0026 template <class _Cont>
0027 _LIBCPP_HIDE_FROM_ABI constexpr auto size(const _Cont& __c) noexcept(noexcept(__c.size())) -> decltype(__c.size()) {
0028   return __c.size();
0029 }
0030 
0031 template <class _Tp, size_t _Sz>
0032 _LIBCPP_HIDE_FROM_ABI constexpr size_t size(const _Tp (&)[_Sz]) noexcept {
0033   return _Sz;
0034 }
0035 
0036 #  if _LIBCPP_STD_VER >= 20
0037 template <class _Cont>
0038 _LIBCPP_HIDE_FROM_ABI constexpr auto
0039 ssize(const _Cont& __c) noexcept(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(
0040     __c.size()))) -> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> {
0041   return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size());
0042 }
0043 
0044 // GCC complains about the implicit conversion from ptrdiff_t to size_t in
0045 // the array bound.
0046 _LIBCPP_DIAGNOSTIC_PUSH
0047 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wsign-conversion")
0048 template <class _Tp, ptrdiff_t _Sz>
0049 _LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept {
0050   return _Sz;
0051 }
0052 _LIBCPP_DIAGNOSTIC_POP
0053 #  endif
0054 
0055 #endif // _LIBCPP_STD_VER >= 17
0056 
0057 _LIBCPP_END_NAMESPACE_STD
0058 
0059 #endif // _LIBCPP___CXX03___ITERATOR_SIZE_H