//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//

// template<class T>
// using iter_value_t;

#include <cuda/std/concepts>
#include <cuda/std/iterator>

template <class T, class Expected>
__host__ __device__ constexpr bool check_iter_value_t()
{
  constexpr bool result = cuda::std::same_as<cuda::std::iter_value_t<T>, Expected>;
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T const>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T volatile>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T const volatile>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T const&>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T volatile&>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T const volatile&>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T const&&>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T volatile&&>, Expected> == result, "");
  static_assert(cuda::std::same_as<cuda::std::iter_value_t<T const volatile&&>, Expected> == result, "");

  return result;
}

static_assert(check_iter_value_t<int*, int>(), "");
static_assert(check_iter_value_t<int[], int>(), "");
static_assert(check_iter_value_t<int[10], int>(), "");

struct both_members
{
  using value_type   = double;
  using element_type = double;
};
static_assert(check_iter_value_t<both_members, double>(), "");

// clang-format off
template <class T, class = void>
_CCCL_INLINE_VAR constexpr bool check_no_iter_value_t = true;

template <class T>
_CCCL_INLINE_VAR constexpr bool check_no_iter_value_t<T, cuda::std::void_t<cuda::std::iter_value_t<T>>> = false;

static_assert(check_no_iter_value_t<void>, "");
static_assert(check_no_iter_value_t<double>, "");

struct S {};
static_assert(check_no_iter_value_t<S>, "");

struct different_value_element_members {
  using value_type = int;
  using element_type = long;
};
static_assert(check_no_iter_value_t<different_value_element_members>, "");

int main(int, char**) { return 0; }
