codekingpro/portable-devtools
114k
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.8//9//===----------------------------------------------------------------------===//10 11#ifndef _LIBCUDACXX___ITERATOR_SIZE_H12#define _LIBCUDACXX___ITERATOR_SIZE_H13 14#ifndef __cuda_std__15#include <__config>16#endif // __cuda_std__17 18#include "../__type_traits/common_type.h"19#include "../__type_traits/make_signed.h"20#include "../cstddef"21 22#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)23# pragma GCC system_header24#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)25# pragma clang system_header26#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)27# pragma system_header28#endif // no system header29 30_LIBCUDACXX_BEGIN_NAMESPACE_STD31 32#if _LIBCUDACXX_STD_VER > 1133template <class _Cont>34_LIBCUDACXX_INLINE_VISIBILITY35constexpr auto size(const _Cont& __c)36noexcept(noexcept(__c.size()))37-> decltype (__c.size())38{ return __c.size(); }39 40template <class _Tp, size_t _Sz>41_LIBCUDACXX_INLINE_VISIBILITY42constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }43#endif // _LIBCUDACXX_STD_VER > 1144 45#if _LIBCUDACXX_STD_VER > 1746template <class _Cont>47_LIBCUDACXX_INLINE_VISIBILITY48constexpr auto ssize(const _Cont& __c)49noexcept(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))50-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>51{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }52 53// GCC complains about the implicit conversion from ptrdiff_t to size_t in54// the array bound.55# if defined(_LIBCUDACXX_COMPILER_GCC)56# pragma GCC diagnostic push57# pragma GCC diagnostic ignored "-Wsign-conversion"58# endif // _LIBCUDACXX_COMPILER_GCC59template <class _Tp, ptrdiff_t _Sz>60_LIBCUDACXX_INLINE_VISIBILITY61constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }62# if defined(_LIBCUDACXX_COMPILER_GCC)63# pragma GCC diagnostic pop64# endif // _LIBCUDACXX_COMPILER_GCC65#endif // _LIBCUDACXX_STD_VER > 1766 67_LIBCUDACXX_END_NAMESPACE_STD68 69#endif // _LIBCUDACXX___ITERATOR_SIZE_H70 