diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/CMakeLists.txt b/libcudacxx/include/cuda/std/detail/libcxx/include/CMakeLists.txt index f9c84eb926..00ddbcb637 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/CMakeLists.txt +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/CMakeLists.txt @@ -187,6 +187,7 @@ set(files __node_handle __nullptr __ranges/enable_borrowed_range.h + __ranges/enable_view.h __split_buffer __sso_allocator __std_stream @@ -453,6 +454,7 @@ set(files ostream queue random + ranges ratio regex scoped_allocator diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/__ranges/enable_view.h b/libcudacxx/include/cuda/std/detail/libcxx/include/__ranges/enable_view.h new file mode 100644 index 0000000000..1b8ad5b2ea --- /dev/null +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/__ranges/enable_view.h @@ -0,0 +1,80 @@ +// -*- 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 +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___RANGES_ENABLE_VIEW_H +#define _LIBCUDACXX___RANGES_ENABLE_VIEW_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/derived_from.h" +#include "../__concepts/same_as.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_class.h" +#include "../__type_traits/remove_cv.h" +#include "../__type_traits/void_t.h" + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES + +#if _LIBCUDACXX_STD_VER > 14 + +struct view_base { }; + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI + +#if _LIBCUDACXX_STD_VER > 17 + +template + requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>> +class view_interface; + +#else + +template && same_as<_Derived, remove_cv_t<_Derived>>, int> = 0> +class view_interface; + +#endif // _LIBCUDACXX_STD_VER < 17 + +_LIBCUDACXX_END_NAMESPACE_RANGES_ABI + +_LIBCUDACXX_TEMPLATE(class _Op, class _Yp) + _LIBCUDACXX_REQUIRES(is_convertible_v<_Op*, view_interface<_Yp>*>) +_LIBCUDACXX_INLINE_VISIBILITY +void __is_derived_from_view_interface(const _Op*, const view_interface<_Yp>*); + +#if _LIBCUDACXX_STD_VER > 17 + +template +_LIBCUDACXX_INLINE_VAR constexpr bool enable_view = derived_from<_Tp, view_base> || + requires { _CUDA_VRANGES::__is_derived_from_view_interface((_Tp*)nullptr, (_Tp*)nullptr); }; + +#else + +template +_LIBCUDACXX_INLINE_VAR constexpr bool enable_view = derived_from<_Tp, view_base>; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool enable_view<_Tp, + void_t> = true; +#endif // _LIBCUDACXX_STD_VER < 17 + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_RANGES + +#endif // _LIBCUDACXX___RANGES_ENABLE_VIEW_H diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/ranges b/libcudacxx/include/cuda/std/detail/libcxx/include/ranges index deb4402fd9..5ffe0d4f5f 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/ranges +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/ranges @@ -312,6 +312,7 @@ namespace std { #include "__assert" // all public C++ headers provide the assertion handler #include "__ranges/enable_borrowed_range.h" +#include "__ranges/enable_view.h" // standard-mandated includes #include "version" diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/span b/libcudacxx/include/cuda/std/detail/libcxx/include/span index 2469ef1a50..22258a81ea 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/span +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/span @@ -144,6 +144,7 @@ template #include "__iterator/wrap_iter.h" #include "__memory/pointer_traits.h" #include "__ranges/enable_borrowed_range.h" +#include "__ranges/enable_view.h" #include "__type_traits/enable_if.h" #include "__type_traits/integral_constant.h" #include "__type_traits/is_array.h" @@ -581,6 +582,9 @@ _LIBCUDACXX_END_NAMESPACE_STD _LIBCUDACXX_BEGIN_NAMESPACE_RANGES template _LIBCUDACXX_INLINE_VAR constexpr bool enable_borrowed_range> = true; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool enable_view> = true; _LIBCUDACXX_END_NAMESPACE_RANGES #endif // _CCCL_STD_VER > 2014 diff --git a/libcudacxx/libcxx/test/std/containers/views/views.span/range_concept_conformance.compile.pass.cpp b/libcudacxx/libcxx/test/std/containers/views/views.span/range_concept_conformance.compile.pass.cpp new file mode 100644 index 0000000000..f98c366cec --- /dev/null +++ b/libcudacxx/libcxx/test/std/containers/views/views.span/range_concept_conformance.compile.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: msvc-19.16 + +// span + +#include + +#include +#include + +using range = std::span; + +#ifdef _LIBCUDACXX_HAS_RANGES +static_assert(std::same_as, range::iterator>); +static_assert(std::ranges::common_range); +static_assert(std::ranges::random_access_range); +static_assert(std::ranges::contiguous_range); +static_assert(std::ranges::view && std::ranges::enable_view); +static_assert(std::ranges::sized_range); +static_assert(std::ranges::borrowed_range); +static_assert(std::ranges::viewable_range); + +static_assert(std::same_as, range::iterator>); +static_assert(std::ranges::common_range); +static_assert(std::ranges::random_access_range); +static_assert(std::ranges::contiguous_range); +static_assert(!std::ranges::view && !std::ranges::enable_view); +static_assert(std::ranges::sized_range); +static_assert(std::ranges::borrowed_range); +static_assert(std::ranges::viewable_range); +#endif // _LIBCUDACXX_HAS_RANGES + +int main(int, char**) +{ + return 0; +} diff --git a/libcudacxx/test/libcudacxx/std/views/views.span/range_concept_conformance.compile.pass.cpp b/libcudacxx/test/libcudacxx/std/views/views.span/range_concept_conformance.compile.pass.cpp new file mode 100644 index 0000000000..329f028155 --- /dev/null +++ b/libcudacxx/test/libcudacxx/std/views/views.span/range_concept_conformance.compile.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// UNSUPPORTED: msvc-19.16 + +// span + +#include + +#include +#include + +using range = cuda::std::span; + +#ifdef _LIBCUDACXX_HAS_RANGES +static_assert(cuda::std::same_as, range::iterator>); +static_assert(cuda::std::ranges::common_range); +static_assert(cuda::std::ranges::random_access_range); +static_assert(cuda::std::ranges::contiguous_range); +static_assert(cuda::std::ranges::view && cuda::std::ranges::enable_view); +static_assert(cuda::std::ranges::sized_range); +static_assert(cuda::std::ranges::borrowed_range); +static_assert(cuda::std::ranges::viewable_range); + +static_assert(cuda::std::same_as, range::iterator>); +static_assert(cuda::std::ranges::common_range); +static_assert(cuda::std::ranges::random_access_range); +static_assert(cuda::std::ranges::contiguous_range); +static_assert(!cuda::std::ranges::view && !cuda::std::ranges::enable_view); +static_assert(cuda::std::ranges::sized_range); +static_assert(cuda::std::ranges::borrowed_range); +static_assert(cuda::std::ranges::viewable_range); +#endif // _LIBCUDACXX_HAS_RANGES + +int main(int, char**) +{ + return 0; +}