2021-06-29 02:32:59 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP___ITERATOR_SIZE_H
|
|
|
|
#define _LIBCPP___ITERATOR_SIZE_H
|
|
|
|
|
|
|
|
#include <__config>
|
2024-10-31 02:20:10 +01:00
|
|
|
#include <__cstddef/ptrdiff_t.h>
|
|
|
|
#include <__cstddef/size_t.h>
|
2022-12-20 21:13:12 +01:00
|
|
|
#include <__type_traits/common_type.h>
|
|
|
|
#include <__type_traits/make_signed.h>
|
2021-06-29 02:32:59 +00:00
|
|
|
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-01 20:16:40 -05:00
|
|
|
# pragma GCC system_header
|
2021-06-29 02:32:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#if _LIBCPP_STD_VER >= 17
|
2021-06-29 02:32:59 +00:00
|
|
|
|
|
|
|
template <class _Cont>
|
2024-06-23 22:03:41 +02:00
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr auto size(const _Cont& __c) noexcept(noexcept(__c.size())) -> decltype(__c.size()) {
|
2021-06-29 02:32:59 +00:00
|
|
|
return __c.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, size_t _Sz>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr size_t size(const _Tp (&)[_Sz]) noexcept {
|
|
|
|
return _Sz;
|
|
|
|
}
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
# if _LIBCPP_STD_VER >= 20
|
2021-06-29 02:32:59 +00:00
|
|
|
template <class _Cont>
|
2024-06-23 22:03:41 +02:00
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr auto
|
|
|
|
ssize(const _Cont& __c) noexcept(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(
|
|
|
|
__c.size()))) -> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> {
|
2021-06-29 02:32:59 +00:00
|
|
|
return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size());
|
|
|
|
}
|
|
|
|
|
2022-03-03 13:39:12 -05:00
|
|
|
// GCC complains about the implicit conversion from ptrdiff_t to size_t in
|
|
|
|
// the array bound.
|
|
|
|
_LIBCPP_DIAGNOSTIC_PUSH
|
|
|
|
_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wsign-conversion")
|
2021-06-29 02:32:59 +00:00
|
|
|
template <class _Tp, ptrdiff_t _Sz>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept {
|
|
|
|
return _Sz;
|
|
|
|
}
|
2022-03-03 13:39:12 -05:00
|
|
|
_LIBCPP_DIAGNOSTIC_POP
|
2021-06-29 02:32:59 +00:00
|
|
|
# endif
|
|
|
|
|
2023-02-14 00:56:09 +01:00
|
|
|
#endif // _LIBCPP_STD_VER >= 17
|
2021-06-29 02:32:59 +00:00
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP___ITERATOR_SIZE_H
|