Skip to content

Commit

Permalink
Do not require contiguous_iterator_tag in C++17 as that is not sati…
Browse files Browse the repository at this point in the history
…sfied by any standard container
  • Loading branch information
miscco committed Oct 23, 2024
1 parent a8dd691 commit 2cadd3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion libcudacxx/include/cuda/std/__iterator/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ _LIBCUDACXX_CONCEPT_FRAGMENT(
__contiguous_iterator_,
requires(const _Ip& __i)(
requires(random_access_iterator<_Ip>),
requires(derived_from<_ITER_CONCEPT<_Ip>, contiguous_iterator_tag>),
requires(is_lvalue_reference_v<iter_reference_t<_Ip>>),
requires(same_as<iter_value_t<_Ip>, remove_cvref_t<iter_reference_t<_Ip>>>),
requires(same_as<add_pointer_t<iter_reference_t<_Ip>>, decltype(_CUDA_VSTD::to_address(__i))>)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#include "test_macros.h"

#if !defined(TEST_COMPILER_NVRTC)
# include <vector>
#endif // !TEST_COMPILER_NVRTC

// Look ma - I'm a container!
template <typename T>
struct IsAContainer
Expand Down Expand Up @@ -136,6 +140,19 @@ __host__ __device__ void testRuntimeSpanStatic()
assert(s2.data() == cVal.getV() && s2.size() == 1);
}

#if !defined(TEST_COMPILER_NVRTC)
template <typename T>
void testContainers()
{
::std::vector<T> val(1);
const ::std::vector<T> cVal(1);
cuda::std::span<T> s1{val};
cuda::std::span<const T> s2{cVal};
assert(s1.data() == val.data() && s1.size() == 1);
assert(s2.data() == cVal.data() && s2.size() == 1);
}
#endif // !TEST_COMPILER_NVRTC

struct A
{};

Expand Down Expand Up @@ -163,5 +180,9 @@ int main(int, char**)

checkCV();

#if !defined(TEST_COMPILER_NVRTC)
NV_IF_TARGET(NV_IS_HOST, (testContainers<int>(); testContainers<A>();))
#endif // !TEST_COMPILER_NVRTC

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ static_assert(cuda::std::indirectly_swappable<reverse_bidirectional_iterator, re
using reverse_random_access_iterator = cuda::std::reverse_iterator<random_access_iterator<int*>>;
static_assert(common_reverse_iterator_checks<reverse_random_access_iterator>());
static_assert(cuda::std::random_access_iterator<reverse_random_access_iterator>);
#if TEST_STD_VER >= 2020 // There is no contiguous_iterator_tag in C++17 so we should not require it
static_assert(!cuda::std::contiguous_iterator<reverse_random_access_iterator>);
#endif // TEST_STD_VER >= 2020
static_assert(cuda::std::sized_sentinel_for<reverse_random_access_iterator, reverse_random_access_iterator>);
static_assert(cuda::std::indirectly_movable<reverse_random_access_iterator, reverse_random_access_iterator>);
static_assert(cuda::std::indirectly_movable_storable<reverse_random_access_iterator, reverse_random_access_iterator>);
Expand All @@ -49,7 +51,9 @@ static_assert(cuda::std::indirectly_swappable<reverse_random_access_iterator, re
using reverse_contiguous_iterator = cuda::std::reverse_iterator<contiguous_iterator<int*>>;
static_assert(common_reverse_iterator_checks<reverse_contiguous_iterator>());
static_assert(cuda::std::random_access_iterator<reverse_contiguous_iterator>);
#if TEST_STD_VER >= 2020 // There is no contiguous_iterator_tag in C++17 so we should not require it
static_assert(!cuda::std::contiguous_iterator<reverse_contiguous_iterator>);
#endif // TEST_STD_VER >= 2020
static_assert(cuda::std::sized_sentinel_for<reverse_contiguous_iterator, reverse_contiguous_iterator>);
static_assert(cuda::std::indirectly_movable<reverse_contiguous_iterator, reverse_contiguous_iterator>);
static_assert(cuda::std::indirectly_movable_storable<reverse_contiguous_iterator, reverse_contiguous_iterator>);
Expand Down

0 comments on commit 2cadd3c

Please sign in to comment.