//===----------------------------------------------------------------------===// // // 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 constexpr bool operator==(const optional& x, const optional& y); #include #include #include #include "cuda/std/__type_traits/reference_constructs_from_temporary.h" #include "test_macros.h" using cuda::std::optional; struct X { int i_; __host__ __device__ constexpr X(int i) : i_(i) {} }; __host__ __device__ constexpr bool operator==(const X& lhs, const X& rhs) { return lhs.i_ == rhs.i_; } template __host__ __device__ constexpr void test() { { using O = optional; cuda::std::remove_reference_t one{1}; cuda::std::remove_reference_t two{2}; O o1{}; // disengaged O o2{}; // disengaged O o3{one}; // engaged O o4{two}; // engaged O o5{one}; // engaged assert(o1 == o1); assert(o1 == o2); assert(!(o1 == o3)); assert(!(o1 == o4)); assert(!(o1 == o5)); assert(o2 == o1); assert(o2 == o2); assert(!(o2 == o3)); assert(!(o2 == o4)); assert(!(o2 == o5)); assert(!(o3 == o1)); assert(!(o3 == o2)); assert(o3 == o3); assert(!(o3 == o4)); assert(o3 == o5); assert(!(o4 == o1)); assert(!(o4 == o2)); assert(!(o4 == o3)); assert(o4 == o4); assert(!(o4 == o5)); assert(!(o5 == o1)); assert(!(o5 == o2)); assert(o5 == o3); assert(!(o5 == o4)); assert(o5 == o5); } { using O1 = optional; using O2 = optional; O1 o1(42); assert(o1 == O2(42)); assert(!(O2(101) == o1)); } { using O1 = optional; using O2 = optional; O1 o1(42); assert(o1 == O2(42)); assert(!(O2(101) == o1)); } } __host__ __device__ constexpr bool test() { test(); #ifdef CCCL_ENABLE_OPTIONAL_REF test(); #endif // CCCL_ENABLE_OPTIONAL_REF return true; } int main(int, char**) { test(); static_assert(test()); return 0; }