diff --git a/.clang-format b/.clang-format index 21fd8c447ad..e1e92e54fc5 100644 --- a/.clang-format +++ b/.clang-format @@ -111,6 +111,9 @@ IncludeCategories: - Regex: '^<(cuda/std/detail/__config|cub/config.cuh|thrust/detail/config.h|thrust/system/cuda/config.h)' Priority: 0 SortPriority: 0 + - Regex: '^' + Priority: 6 + SortPriority: 5 - Regex: '^`](https://en.cppreference.com/w/cpp/header/cfloat) | Limits of floating point types.

1.0.0 / CUDA 10.2 | | [``](https://en.cppreference.com/w/cpp/header/climits) | Limits of integral types.

1.0.0 / CUDA 10.2 | | [``](https://en.cppreference.com/w/cpp/header/cstdint) | Fixed-width integer types.

1.0.0 / CUDA 10.2 | - - -[``]: https://en.cppreference.com/w/cpp/header/complex -[``]: https://en.cppreference.com/w/cpp/header/ccomplex -[``]: https://en.cppreference.com/w/cpp/header/ratio -[``]: https://en.cppreference.com/w/cpp/header/cfloat -[``]: https://en.cppreference.com/w/cpp/header/climits -[``]: https://en.cppreference.com/w/cpp/header/cstdint +| [``](https://en.cppreference.com/w/cpp/header/numeric) | Numeric algorithms (see also: [libcu++ Specifics]({{ "standard_api/numerics_library/numeric.html" | relative_url }})).

2.5.0 | diff --git a/libcudacxx/docs/standard_api/numerics_library/numeric.md b/libcudacxx/docs/standard_api/numerics_library/numeric.md new file mode 100644 index 00000000000..f4b3063d161 --- /dev/null +++ b/libcudacxx/docs/standard_api/numerics_library/numeric.md @@ -0,0 +1,18 @@ +--- +grand_parent: Standard API +parent: Numerics Library +nav_order: 3 +--- + +# `` + +## Omissions + +* Currently we do not expose any parallel algorithms. +* Saturation arithmetics have not been implemented yet + +## Extensions + +* All features of `` are made available in C++11 onwards +* All features of `` are made constexpr in C++14 onwards +* Algorithms that return a value have been marked `[[nodiscard]]` diff --git a/libcudacxx/include/cuda/std/__algorithm/max.h b/libcudacxx/include/cuda/std/__algorithm/max.h index e14ba2f0dcb..9fbe66ee1ed 100644 --- a/libcudacxx/include/cuda/std/__algorithm/max.h +++ b/libcudacxx/include/cuda/std/__algorithm/max.h @@ -23,9 +23,10 @@ #include #include #include -#include #include +#include + _LIBCUDACXX_BEGIN_NAMESPACE_STD template diff --git a/libcudacxx/include/cuda/std/__algorithm/min.h b/libcudacxx/include/cuda/std/__algorithm/min.h index 62401fe70f6..738194b83a5 100644 --- a/libcudacxx/include/cuda/std/__algorithm/min.h +++ b/libcudacxx/include/cuda/std/__algorithm/min.h @@ -23,9 +23,10 @@ #include #include #include -#include #include +#include + _LIBCUDACXX_BEGIN_NAMESPACE_STD template diff --git a/libcudacxx/include/cuda/std/__algorithm/min_element.h b/libcudacxx/include/cuda/std/__algorithm/min_element.h index 60a3e00b1ed..271740dafe5 100644 --- a/libcudacxx/include/cuda/std/__algorithm/min_element.h +++ b/libcudacxx/include/cuda/std/__algorithm/min_element.h @@ -27,6 +27,7 @@ #include #include #include + #include _LIBCUDACXX_BEGIN_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/__functional/operations.h b/libcudacxx/include/cuda/std/__functional/operations.h index ed90b0a33c0..978a53f993d 100644 --- a/libcudacxx/include/cuda/std/__functional/operations.h +++ b/libcudacxx/include/cuda/std/__functional/operations.h @@ -29,11 +29,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD // Arithmetic operations -#if _CCCL_STD_VER > 2011 template -#else -template -#endif struct _LIBCUDACXX_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray @@ -45,7 +41,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> }; _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(plus); -#if _CCCL_STD_VER > 2011 template <> struct _LIBCUDACXX_TEMPLATE_VIS plus { @@ -59,7 +54,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS plus } typedef void is_transparent; }; -#endif #if _CCCL_STD_VER > 2011 template @@ -93,11 +87,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS minus }; #endif -#if _CCCL_STD_VER > 2011 template -#else -template -#endif struct _LIBCUDACXX_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> { typedef _Tp __result_type; // used by valarray @@ -109,7 +99,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> }; _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(multiplies); -#if _CCCL_STD_VER > 2011 template <> struct _LIBCUDACXX_TEMPLATE_VIS multiplies { @@ -123,7 +112,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS multiplies } typedef void is_transparent; }; -#endif #if _CCCL_STD_VER > 2011 template @@ -189,11 +177,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS modulus }; #endif -#if _CCCL_STD_VER > 2011 template -#else -template -#endif struct _LIBCUDACXX_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> { typedef _Tp __result_type; // used by valarray @@ -205,7 +189,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> }; _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(negate); -#if _CCCL_STD_VER > 2011 template <> struct _LIBCUDACXX_TEMPLATE_VIS negate { @@ -218,7 +201,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS negate } typedef void is_transparent; }; -#endif // Bitwise operations diff --git a/libcudacxx/include/cuda/std/__mdspan/layout_stride.h b/libcudacxx/include/cuda/std/__mdspan/layout_stride.h index 4b560e9bb30..4bf9d714528 100644 --- a/libcudacxx/include/cuda/std/__mdspan/layout_stride.h +++ b/libcudacxx/include/cuda/std/__mdspan/layout_stride.h @@ -69,7 +69,7 @@ #include #include #include -#include +#include #if __MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20 # include #endif // __MDSPAN_USE_CONCEPTS && __MDSPAN_HAS_CXX_20 diff --git a/libcudacxx/include/cuda/std/__numeric/accumulate.h b/libcudacxx/include/cuda/std/__numeric/accumulate.h new file mode 100644 index 00000000000..9dc66281e33 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/accumulate.h @@ -0,0 +1,53 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_ACCUMULATE_H +#define _LIBCUDACXX___NUMERIC_ACCUMULATE_H + +#include + +#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 + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp +accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) +{ + for (; __first != __last; ++__first) + { + __init = _CUDA_VSTD::move(__init) + *__first; + } + return __init; +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp +accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) +{ + for (; __first != __last; ++__first) + { + __init = __binary_op(_CUDA_VSTD::move(__init), *__first); + } + return __init; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_ACCUMULATE_H diff --git a/libcudacxx/include/cuda/std/__numeric/adjacent_difference.h b/libcudacxx/include/cuda/std/__numeric/adjacent_difference.h new file mode 100644 index 00000000000..caf801a8afd --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/adjacent_difference.h @@ -0,0 +1,68 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_ADJACENT_DIFFERENCE_H +#define _LIBCUDACXX___NUMERIC_ADJACENT_DIFFERENCE_H + +#include + +#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 + +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __acc(*__first); + *__result = __acc; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + typename iterator_traits<_InputIterator>::value_type __val(*__first); + *__result = __val - _CUDA_VSTD::move(__acc); + __acc = _CUDA_VSTD::move(__val); + } + } + return __result; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator adjacent_difference( + _InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __acc(*__first); + *__result = __acc; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + typename iterator_traits<_InputIterator>::value_type __val(*__first); + *__result = __binary_op(__val, _CUDA_VSTD::move(__acc)); + __acc = _CUDA_VSTD::move(__val); + } + } + return __result; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_ADJACENT_DIFFERENCE_H diff --git a/libcudacxx/include/cuda/std/__numeric/exclusive_scan.h b/libcudacxx/include/cuda/std/__numeric/exclusive_scan.h new file mode 100644 index 00000000000..73392bff487 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/exclusive_scan.h @@ -0,0 +1,62 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_EXCLUSIVE_SCAN_H +#define _LIBCUDACXX___NUMERIC_EXCLUSIVE_SCAN_H + +#include + +#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 + +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) +{ + if (__first != __last) + { + _Tp __tmp(__b(__init, *__first)); + while (true) + { + *__result = _CUDA_VSTD::move(__init); + ++__result; + ++__first; + if (__first == __last) + { + break; + } + __init = _CUDA_VSTD::move(__tmp); + __tmp = __b(__init, *__first); + } + } + return __result; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) +{ + return _CUDA_VSTD::exclusive_scan(__first, __last, __result, __init, _CUDA_VSTD::plus<>()); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_EXCLUSIVE_SCAN_H diff --git a/libcudacxx/include/cuda/std/__numeric/gcd_lcm.h b/libcudacxx/include/cuda/std/__numeric/gcd_lcm.h new file mode 100644 index 00000000000..f4a23fd73b6 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/gcd_lcm.h @@ -0,0 +1,112 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_GCD_LCM_H +#define _LIBCUDACXX___NUMERIC_GCD_LCM_H + +#include + +#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 + +#include +#include +#include +#include +#include +#include + +// comes last +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct __ct_abs; + +template +struct __ct_abs<_Result, _Source, true> +{ + _CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Source __t) const noexcept + { + if (__t >= 0) + { + return __t; + } + _CCCL_DIAG_PUSH + _CCCL_DIAG_SUPPRESS_MSVC(4146) // unary minus operator applied to unsigned type, result still unsigned + if (__t == (numeric_limits<_Source>::min)()) + { + return -static_cast<_Result>(__t); + } + _CCCL_DIAG_POP + return -__t; + } +}; + +template +struct __ct_abs<_Result, _Source, false> +{ + _CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Source __t) const noexcept + { + return __t; + } +}; + +template +_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp __gcd(_Tp __m, _Tp __n) +{ + static_assert((!_LIBCUDACXX_TRAIT(is_signed, _Tp)), ""); + return __n == 0 ? __m : _CUDA_VSTD::__gcd<_Tp>(__n, __m % __n); +} + +template +_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY __common_type_t<_Tp, _Up> gcd(_Tp __m, _Up __n) +{ + static_assert((_LIBCUDACXX_TRAIT(is_integral, _Tp) && _LIBCUDACXX_TRAIT(is_integral, _Up)), + "Arguments to gcd must be integer types"); + static_assert((!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t<_Tp>, bool)), "First argument to gcd cannot be bool"); + static_assert((!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t<_Up>, bool)), "Second argument to gcd cannot be bool"); + using _Rp = __common_type_t<_Tp, _Up>; + using _Wp = __make_unsigned_t<_Rp>; + return static_cast<_Rp>( + _CUDA_VSTD::__gcd(static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)), static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n)))); +} + +template +_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY __common_type_t<_Tp, _Up> lcm(_Tp __m, _Up __n) +{ + static_assert((_LIBCUDACXX_TRAIT(is_integral, _Tp) && _LIBCUDACXX_TRAIT(is_integral, _Up)), + "Arguments to lcm must be integer types"); + static_assert((!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t<_Tp>, bool)), "First argument to lcm cannot be bool"); + static_assert((!_LIBCUDACXX_TRAIT(is_same, __remove_cv_t<_Up>, bool)), "Second argument to lcm cannot be bool"); + if (__m == 0 || __n == 0) + { + return 0; + } + + using _Rp = __common_type_t<_Tp, _Up>; + _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _CUDA_VSTD::gcd(__m, __n); + _Rp __val2 = __ct_abs<_Rp, _Up>()(__n); + _LIBCUDACXX_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); + return __val1 * __val2; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#include + +#endif // _LIBCUDACXX___NUMERIC_GCD_LCM_H diff --git a/libcudacxx/include/cuda/std/__numeric/inclusive_scan.h b/libcudacxx/include/cuda/std/__numeric/inclusive_scan.h new file mode 100644 index 00000000000..bbf5b678a08 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/inclusive_scan.h @@ -0,0 +1,69 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_INCLUSIVE_SCAN_H +#define _LIBCUDACXX___NUMERIC_INCLUSIVE_SCAN_H + +#include + +#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 + +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) +{ + for (; __first != __last; ++__first, (void) ++__result) + { + __init = __b(__init, *__first); + *__result = __init; + } + return __result; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __init = *__first; + *__result++ = __init; + if (++__first != __last) + { + return _CUDA_VSTD::inclusive_scan(__first, __last, __result, __b, __init); + } + } + + return __result; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + return _CUDA_VSTD::inclusive_scan(__first, __last, __result, _CUDA_VSTD::plus<>()); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_INCLUSIVE_SCAN_H diff --git a/libcudacxx/include/cuda/std/__numeric/inner_product.h b/libcudacxx/include/cuda/std/__numeric/inner_product.h new file mode 100644 index 00000000000..a968294cb38 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/inner_product.h @@ -0,0 +1,58 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_INNER_PRODUCT_H +#define _LIBCUDACXX___NUMERIC_INNER_PRODUCT_H + +#include + +#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 + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp +inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + { + __init = _CUDA_VSTD::move(__init) + *__first1 * *__first2; + } + return __init; +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp inner_product( + _InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _Tp __init, + _BinaryOperation1 __binary_op1, + _BinaryOperation2 __binary_op2) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + { + __init = __binary_op1(_CUDA_VSTD::move(__init), __binary_op2(*__first1, *__first2)); + } + return __init; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_INNER_PRODUCT_H diff --git a/libcudacxx/include/cuda/std/__numeric/iota.h b/libcudacxx/include/cuda/std/__numeric/iota.h new file mode 100644 index 00000000000..3fcab420484 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/iota.h @@ -0,0 +1,39 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_IOTA_H +#define _LIBCUDACXX___NUMERIC_IOTA_H + +#include + +#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_STD + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 void +iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) +{ + for (; __first != __last; ++__first, (void) ++__value_) + { + *__first = __value_; + } +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_IOTA_H diff --git a/libcudacxx/include/cuda/std/__numeric/midpoint.h b/libcudacxx/include/cuda/std/__numeric/midpoint.h new file mode 100644 index 00000000000..385c851fde4 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/midpoint.h @@ -0,0 +1,104 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_MIDPOINT_H +#define _LIBCUDACXX___NUMERIC_MIDPOINT_H + +#include + +#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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// comes last +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 + __enable_if_t<_LIBCUDACXX_TRAIT(is_integral, _Tp) && !_LIBCUDACXX_TRAIT(is_same, bool, _Tp) + && !_LIBCUDACXX_TRAIT(is_null_pointer, _Tp), + _Tp> + midpoint(_Tp __a, _Tp __b) noexcept +{ + using _Up = __make_unsigned_t<_Tp>; + + if (__a > __b) + { + const _Up __diff = _Up(__a) - _Up(__b); + return static_cast<_Tp>(__a - static_cast<_Tp>(__diff / 2)); + } + else + { + const _Up __diff = _Up(__b) - _Up(__a); + return static_cast<_Tp>(__a + static_cast<_Tp>(__diff / 2)); + } +} + +template < + class _Tp, + __enable_if_t<_LIBCUDACXX_TRAIT(is_object, _Tp) && !_LIBCUDACXX_TRAIT(is_void, _Tp) && (sizeof(_Tp) > 0), int> = 0> +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp* midpoint(_Tp* __a, _Tp* __b) noexcept +{ + return __a + _CUDA_VSTD::midpoint(ptrdiff_t(0), __b - __a); +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 int __sign(_Tp __val) +{ + return (_Tp(0) < __val) - (__val < _Tp(0)); +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Fp __fp_abs(_Fp __f) +{ + return __f >= 0 ? __f : -__f; +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 + __enable_if_t<_LIBCUDACXX_TRAIT(is_floating_point, _Fp), _Fp> + midpoint(_Fp __a, _Fp __b) noexcept +{ + _CCCL_CONSTEXPR_CXX14 _Fp __lo = numeric_limits<_Fp>::min() * 2; + _CCCL_CONSTEXPR_CXX14 _Fp __hi = numeric_limits<_Fp>::max() / 2; + return _CUDA_VSTD::__fp_abs(__a) <= __hi && _CUDA_VSTD::__fp_abs(__b) <= __hi + ? // typical case: overflow is impossible + (__a + __b) / 2 + : // always correctly rounded + _CUDA_VSTD::__fp_abs(__a) < __lo ? __a + __b / 2 : // not safe to halve a + _CUDA_VSTD::__fp_abs(__b) < __lo + ? __a / 2 + __b + : // not safe to halve b + __a / 2 + __b / 2; // otherwise correctly rounded +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#include + +#endif // _LIBCUDACXX___NUMERIC_MIDPOINT_H diff --git a/libcudacxx/include/cuda/std/__numeric/partial_sum.h b/libcudacxx/include/cuda/std/__numeric/partial_sum.h new file mode 100644 index 00000000000..8cd0dfbe06a --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/partial_sum.h @@ -0,0 +1,66 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_PARTIAL_SUM_H +#define _LIBCUDACXX___NUMERIC_PARTIAL_SUM_H + +#include + +#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 + +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + __t = _CUDA_VSTD::move(__t) + *__first; + *__result = __t; + } + } + return __result; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator +partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + __t = __binary_op(_CUDA_VSTD::move(__t), *__first); + *__result = __t; + } + } + return __result; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_PARTIAL_SUM_H diff --git a/libcudacxx/include/cuda/std/__numeric/reduce.h b/libcudacxx/include/cuda/std/__numeric/reduce.h new file mode 100644 index 00000000000..a95b54405a4 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/reduce.h @@ -0,0 +1,58 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_REDUCE_H +#define _LIBCUDACXX___NUMERIC_REDUCE_H + +#include + +#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 + +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp +reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) +{ + for (; __first != __last; ++__first) + { + __init = __b(_CUDA_VSTD::move(__init), *__first); + } + return __init; +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp +reduce(_InputIterator __first, _InputIterator __last, _Tp __init) +{ + return _CUDA_VSTD::reduce(__first, __last, __init, _CUDA_VSTD::plus<>()); +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 typename iterator_traits<_InputIterator>::value_type +reduce(_InputIterator __first, _InputIterator __last) +{ + return _CUDA_VSTD::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{}); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_REDUCE_H diff --git a/libcudacxx/include/cuda/std/__numeric/transform_exclusive_scan.h b/libcudacxx/include/cuda/std/__numeric/transform_exclusive_scan.h new file mode 100644 index 00000000000..427ea9691cd --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/transform_exclusive_scan.h @@ -0,0 +1,47 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H +#define _LIBCUDACXX___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H + +#include + +#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_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator transform_exclusive_scan( + _InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, __u(*__first)); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H diff --git a/libcudacxx/include/cuda/std/__numeric/transform_inclusive_scan.h b/libcudacxx/include/cuda/std/__numeric/transform_inclusive_scan.h new file mode 100644 index 00000000000..165285d76b1 --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/transform_inclusive_scan.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H +#define _LIBCUDACXX___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H + +#include + +#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 + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator transform_inclusive_scan( + _InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init) +{ + for (; __first != __last; ++__first, (void) ++__result) + { + __init = __b(__init, __u(*__first)); + *__result = __init; + } + + return __result; +} + +template +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _OutputIterator transform_inclusive_scan( + _InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __init = __u(*__first); + *__result++ = __init; + if (++__first != __last) + { + return _CUDA_VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init); + } + } + + return __result; +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H diff --git a/libcudacxx/include/cuda/std/__numeric/transform_reduce.h b/libcudacxx/include/cuda/std/__numeric/transform_reduce.h new file mode 100644 index 00000000000..d90019aae0f --- /dev/null +++ b/libcudacxx/include/cuda/std/__numeric/transform_reduce.h @@ -0,0 +1,68 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// 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) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___NUMERIC_TRANSFORM_REDUCE_H +#define _LIBCUDACXX___NUMERIC_TRANSFORM_REDUCE_H + +#include + +#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 + +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp +transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b, _UnaryOp __u) +{ + for (; __first != __last; ++__first) + { + __init = __b(_CUDA_VSTD::move(__init), __u(*__first)); + } + return __init; +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp transform_reduce( + _InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _Tp __init, + _BinaryOp1 __b1, + _BinaryOp2 __b2) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) + { + __init = __b1(_CUDA_VSTD::move(__init), __b2(*__first1, *__first2)); + } + return __init; +} + +template +_CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp +transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) +{ + return _CUDA_VSTD::transform_reduce( + __first1, __last1, __first2, _CUDA_VSTD::move(__init), _CUDA_VSTD::plus<>(), _CUDA_VSTD::multiplies<>()); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___NUMERIC_TRANSFORM_REDUCE_H diff --git a/libcudacxx/include/cuda/std/__type_traits/is_null_pointer.h b/libcudacxx/include/cuda/std/__type_traits/is_null_pointer.h index 9b9ed837d81..46f2f5ca847 100644 --- a/libcudacxx/include/cuda/std/__type_traits/is_null_pointer.h +++ b/libcudacxx/include/cuda/std/__type_traits/is_null_pointer.h @@ -37,11 +37,9 @@ template struct _LIBCUDACXX_TEMPLATE_VIS __is_nullptr_t : public __is_nullptr_t_impl<__remove_cv_t<_Tp>> {}; -#if _CCCL_STD_VER > 2011 template struct _LIBCUDACXX_TEMPLATE_VIS is_null_pointer : public __is_nullptr_t_impl<__remove_cv_t<_Tp>> {}; -#endif #if _CCCL_STD_VER > 2011 && !defined(_LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES) template diff --git a/libcudacxx/include/cuda/std/__utility/cmp.h b/libcudacxx/include/cuda/std/__utility/cmp.h index fe876404b97..c086eb6ebd8 100644 --- a/libcudacxx/include/cuda/std/__utility/cmp.h +++ b/libcudacxx/include/cuda/std/__utility/cmp.h @@ -27,9 +27,10 @@ #include #include #include -#include #include +#include + _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _CCCL_STD_VER > 2017 diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/__debug b/libcudacxx/include/cuda/std/detail/libcxx/include/__debug index 8e207184c81..afbc14b6373 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/__debug +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/__debug @@ -21,22 +21,22 @@ # pragma system_header #endif // no system header -#include #include #include +#include #if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) && !defined(_LIBCUDACXX_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY) -# define _LIBCUDACXX_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY +# define _LIBCUDACXX_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY #endif #if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) && !defined(_LIBCUDACXX_DEBUG_ITERATOR_BOUNDS_CHECKING) -# define _LIBCUDACXX_DEBUG_ITERATOR_BOUNDS_CHECKING +# define _LIBCUDACXX_DEBUG_ITERATOR_BOUNDS_CHECKING #endif #ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE -# define _LIBCUDACXX_DEBUG_ASSERT(x, m) _LIBCUDACXX_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m) +# define _LIBCUDACXX_DEBUG_ASSERT(x, m) _LIBCUDACXX_ASSERT(::std::__libcpp_is_constant_evaluated() || (x), m) #else -# define _LIBCUDACXX_DEBUG_ASSERT(x, m) ((void)0) +# define _LIBCUDACXX_DEBUG_ASSERT(x, m) ((void) 0) #endif #if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE) || defined(_LIBCUDACXX_BUILDING_LIBRARY) @@ -47,164 +47,165 @@ struct _LIBCUDACXX_TYPE_VIS __c_node; struct _LIBCUDACXX_TYPE_VIS __i_node { - void* __i_; - __i_node* __next_; - __c_node* __c_; - - __i_node(const __i_node&) = delete; - __i_node& operator=(const __i_node&) = delete; - - _LIBCUDACXX_INLINE_VISIBILITY - __i_node(void* __i, __i_node* __next, __c_node* __c) - : __i_(__i), __next_(__next), __c_(__c) {} - ~__i_node(); + void* __i_; + __i_node* __next_; + __c_node* __c_; + + __i_node(const __i_node&) = delete; + __i_node& operator=(const __i_node&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY __i_node(void* __i, __i_node* __next, __c_node* __c) + : __i_(__i) + , __next_(__next) + , __c_(__c) + {} + ~__i_node(); }; struct _LIBCUDACXX_TYPE_VIS __c_node { - void* __c_; - __c_node* __next_; - __i_node** beg_; - __i_node** end_; - __i_node** cap_; - - __c_node(const __c_node&) = delete; - __c_node& operator=(const __c_node&) = delete; - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __c_node(void* __c, __c_node* __next) - : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {} - virtual ~__c_node(); - - virtual bool __dereferenceable(const void*) const = 0; - virtual bool __decrementable(const void*) const = 0; - virtual bool __addable(const void*, ptrdiff_t) const = 0; - virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; - - void __add(__i_node* __i); - _LIBCUDACXX_HIDDEN void __remove(__i_node* __i); + void* __c_; + __c_node* __next_; + __i_node** beg_; + __i_node** end_; + __i_node** cap_; + + __c_node(const __c_node&) = delete; + __c_node& operator=(const __c_node&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY explicit __c_node(void* __c, __c_node* __next) + : __c_(__c) + , __next_(__next) + , beg_(nullptr) + , end_(nullptr) + , cap_(nullptr) + {} + virtual ~__c_node(); + + virtual bool __dereferenceable(const void*) const = 0; + virtual bool __decrementable(const void*) const = 0; + virtual bool __addable(const void*, ptrdiff_t) const = 0; + virtual bool __subscriptable(const void*, ptrdiff_t) const = 0; + + void __add(__i_node* __i); + _LIBCUDACXX_HIDDEN void __remove(__i_node* __i); }; template -struct _C_node - : public __c_node +struct _C_node : public __c_node { - explicit _C_node(void* __c, __c_node* __n) - : __c_node(__c, __n) {} - - bool __dereferenceable(const void*) const override; - bool __decrementable(const void*) const override; - bool __addable(const void*, ptrdiff_t) const override; - bool __subscriptable(const void*, ptrdiff_t) const override; + explicit _C_node(void* __c, __c_node* __n) + : __c_node(__c, __n) + {} + + bool __dereferenceable(const void*) const override; + bool __decrementable(const void*) const override; + bool __addable(const void*, ptrdiff_t) const override; + bool __subscriptable(const void*, ptrdiff_t) const override; }; template -inline bool -_C_node<_Cont>::__dereferenceable(const void* __i) const +inline bool _C_node<_Cont>::__dereferenceable(const void* __i) const { - typedef typename _Cont::const_iterator iterator; - const iterator* __j = static_cast(__i); - _Cont* _Cp = static_cast<_Cont*>(__c_); - return _Cp->__dereferenceable(__j); + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__dereferenceable(__j); } template -inline bool -_C_node<_Cont>::__decrementable(const void* __i) const +inline bool _C_node<_Cont>::__decrementable(const void* __i) const { - typedef typename _Cont::const_iterator iterator; - const iterator* __j = static_cast(__i); - _Cont* _Cp = static_cast<_Cont*>(__c_); - return _Cp->__decrementable(__j); + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__decrementable(__j); } template -inline bool -_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const +inline bool _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const { - typedef typename _Cont::const_iterator iterator; - const iterator* __j = static_cast(__i); - _Cont* _Cp = static_cast<_Cont*>(__c_); - return _Cp->__addable(__j, __n); + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__addable(__j, __n); } template -inline bool -_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const +inline bool _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const { - typedef typename _Cont::const_iterator iterator; - const iterator* __j = static_cast(__i); - _Cont* _Cp = static_cast<_Cont*>(__c_); - return _Cp->__subscriptable(__j, __n); + typedef typename _Cont::const_iterator iterator; + const iterator* __j = static_cast(__i); + _Cont* _Cp = static_cast<_Cont*>(__c_); + return _Cp->__subscriptable(__j, __n); } class _LIBCUDACXX_TYPE_VIS __libcpp_db { - __c_node** __cbeg_; - __c_node** __cend_; - size_t __csz_; - __i_node** __ibeg_; - __i_node** __iend_; - size_t __isz_; - - explicit __libcpp_db(); + __c_node** __cbeg_; + __c_node** __cend_; + size_t __csz_; + __i_node** __ibeg_; + __i_node** __iend_; + size_t __isz_; + + explicit __libcpp_db(); + public: - __libcpp_db(const __libcpp_db&) = delete; - __libcpp_db& operator=(const __libcpp_db&) = delete; + __libcpp_db(const __libcpp_db&) = delete; + __libcpp_db& operator=(const __libcpp_db&) = delete; - ~__libcpp_db(); + ~__libcpp_db(); - class __db_c_iterator; - class __db_c_const_iterator; - class __db_i_iterator; - class __db_i_const_iterator; + class __db_c_iterator; + class __db_c_const_iterator; + class __db_i_iterator; + class __db_i_const_iterator; - __db_c_const_iterator __c_end() const; - __db_i_const_iterator __i_end() const; + __db_c_const_iterator __c_end() const; + __db_i_const_iterator __i_end() const; - typedef __c_node*(_InsertConstruct)(void*, void*, __c_node*); + typedef __c_node*(_InsertConstruct) (void*, void*, __c_node*); - template - _LIBCUDACXX_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) { - return ::new (__mem) _C_node<_Cont>(__c, __next); - } + template + _LIBCUDACXX_INLINE_VISIBILITY static __c_node* __create_C_node(void* __mem, void* __c, __c_node* __next) + { + return ::new (__mem) _C_node<_Cont>(__c, __next); + } - template - _LIBCUDACXX_INLINE_VISIBILITY - void __insert_c(_Cont* __c) - { - __insert_c(static_cast(__c), &__create_C_node<_Cont>); - } + template + _LIBCUDACXX_INLINE_VISIBILITY void __insert_c(_Cont* __c) + { + __insert_c(static_cast(__c), &__create_C_node<_Cont>); + } - void __insert_i(void* __i); - void __insert_c(void* __c, _InsertConstruct* __fn); - void __erase_c(void* __c); + void __insert_i(void* __i); + void __insert_c(void* __c, _InsertConstruct* __fn); + void __erase_c(void* __c); - void __insert_ic(void* __i, const void* __c); - void __iterator_copy(void* __i, const void* __i0); - void __erase_i(void* __i); + void __insert_ic(void* __i, const void* __c); + void __iterator_copy(void* __i, const void* __i0); + void __erase_i(void* __i); - void* __find_c_from_i(void* __i) const; - void __invalidate_all(void* __c); - __c_node* __find_c_and_lock(void* __c) const; - __c_node* __find_c(void* __c) const; - void unlock() const; + void* __find_c_from_i(void* __i) const; + void __invalidate_all(void* __c); + __c_node* __find_c_and_lock(void* __c) const; + __c_node* __find_c(void* __c) const; + void unlock() const; - void swap(void* __c1, void* __c2); + void swap(void* __c1, void* __c2); + bool __dereferenceable(const void* __i) const; + bool __decrementable(const void* __i) const; + bool __addable(const void* __i, ptrdiff_t __n) const; + bool __subscriptable(const void* __i, ptrdiff_t __n) const; + bool __less_than_comparable(const void* __i, const void* __j) const; - bool __dereferenceable(const void* __i) const; - bool __decrementable(const void* __i) const; - bool __addable(const void* __i, ptrdiff_t __n) const; - bool __subscriptable(const void* __i, ptrdiff_t __n) const; - bool __less_than_comparable(const void* __i, const void* __j) const; private: - _LIBCUDACXX_HIDDEN - __i_node* __insert_iterator(void* __i); - _LIBCUDACXX_HIDDEN - __i_node* __find_iterator(const void* __i) const; + _LIBCUDACXX_HIDDEN __i_node* __insert_iterator(void* __i); + _LIBCUDACXX_HIDDEN __i_node* __find_iterator(const void* __i) const; - friend _LIBCUDACXX_FUNC_VIS __libcpp_db* __get_db(); + friend _LIBCUDACXX_FUNC_VIS __libcpp_db* __get_db(); }; _LIBCUDACXX_FUNC_VIS __libcpp_db* __get_db(); @@ -217,58 +218,68 @@ _LIBCUDACXX_END_NAMESPACE_STD _LIBCUDACXX_BEGIN_NAMESPACE_STD template -_LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 inline void __debug_db_insert_c(_Tp* __c) { +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 inline void __debug_db_insert_c(_Tp* __c) +{ #ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE - if (!__libcpp_is_constant_evaluated()) - __get_db()->__insert_c(__c); + if (!__libcpp_is_constant_evaluated()) + { + __get_db()->__insert_c(__c); + } #else - (void)(__c); + (void) (__c); #endif } template -_LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 inline void __debug_db_insert_i(_Tp* __i) { +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 inline void __debug_db_insert_i(_Tp* __i) +{ #ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE - if (!__libcpp_is_constant_evaluated()) - __get_db()->__insert_i(__i); + if (!__libcpp_is_constant_evaluated()) + { + __get_db()->__insert_i(__i); + } #else - (void)(__i); + (void) (__i); #endif } template -_LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 inline void __debug_db_erase_c(_Tp* __c) { +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 inline void __debug_db_erase_c(_Tp* __c) +{ #ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE - if (!__libcpp_is_constant_evaluated()) - __get_db()->__erase_c(__c); + if (!__libcpp_is_constant_evaluated()) + { + __get_db()->__erase_c(__c); + } #else - (void)(__c); + (void) (__c); #endif } template -_LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) { +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) +{ #ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE - if (!__libcpp_is_constant_evaluated()) - __get_db()->swap(__lhs, __rhs); + if (!__libcpp_is_constant_evaluated()) + { + __get_db()->swap(__lhs, __rhs); + } #else - (void)(__lhs); - (void)(__rhs); + (void) (__lhs); + (void) (__rhs); #endif } template -_LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 inline void __debug_db_invalidate_all(_Tp* __c) { +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 inline void __debug_db_invalidate_all(_Tp* __c) +{ #ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE - if (!__libcpp_is_constant_evaluated()) - __get_db()->__invalidate_all(__c); + if (!__libcpp_is_constant_evaluated()) + { + __get_db()->__invalidate_all(__c); + } #else - (void)(__c); + (void) (__c); #endif } diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/__functional_base b/libcudacxx/include/cuda/std/detail/libcxx/include/__functional_base index 042b7f21c0e..975f8edb813 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/__functional_base +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/__functional_base @@ -35,12 +35,4 @@ #include #include -#include - -_LIBCUDACXX_BEGIN_NAMESPACE_STD - -_LIBCUDACXX_END_NAMESPACE_STD - -#include - -#endif // _LIBCUDACXX_FUNCTIONAL_BASE +#endif // _LIBCUDACXX_FUNCTIONAL_BASE diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/__pragma_push b/libcudacxx/include/cuda/std/detail/libcxx/include/__pragma_push index 9b4ee961937..1c815653a89 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/__pragma_push +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/__pragma_push @@ -8,18 +8,18 @@ //===----------------------------------------------------------------------===// #ifdef _LIBCUDACXX_IMPLICIT_SYSTEM_HEADER - #pragma GCC system_header +# pragma GCC system_header #endif #if defined(_LIBCUDACXX_USE_PRAGMA_MSVC_WARNING) - #pragma warning(push) - #pragma warning(disable : _LIBCUDACXX_MSVC_DISABLED_WARNINGS) +# pragma warning(push) +# pragma warning(disable : _LIBCUDACXX_MSVC_DISABLED_WARNINGS) #endif #if defined(_LIBCUDACXX_PUSH_MACROS) - _LIBCUDACXX_PUSH_MACROS +_LIBCUDACXX_PUSH_MACROS #endif #ifndef __cuda_std__ -#include <__undef_macros> +# include <__undef_macros> #endif diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/__threading_support b/libcudacxx/include/cuda/std/detail/libcxx/include/__threading_support index 18bafb86ae3..47b058648f9 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/__threading_support +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/__threading_support @@ -20,54 +20,53 @@ # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include #include +#include // all public C++ headers provide the assertion handler #include #include #if defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) -# ifndef __cuda_std__ -# include <__external_threading> -# else -# define _LIBCUDACXX_THREAD_ABI_VISIBILITY inline _LIBCUDACXX_INLINE_VISIBILITY -# endif +# ifndef __cuda_std__ +# include <__external_threading> +# else +# define _LIBCUDACXX_THREAD_ABI_VISIBILITY inline _LIBCUDACXX_INLINE_VISIBILITY +# endif #elif !defined(_LIBCUDACXX_HAS_NO_THREADS) -#if defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) -# include -# include -# include -# if defined(__APPLE__) -# include -# endif -# if defined(__linux__) -# include -# include -# include -# endif -#endif - -#if defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) -# include -# include -#endif - -#if defined(_LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL) || \ - defined(_LIBCUDACXX_BUILDING_THREAD_LIBRARY_EXTERNAL) -#define _LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_FUNC_VIS -#else -#define _LIBCUDACXX_THREAD_ABI_VISIBILITY inline _LIBCUDACXX_INLINE_VISIBILITY -#endif - -#if defined(__FreeBSD__) && defined(_CCCL_COMPILER_CLANG) && __has_attribute(no_thread_safety_analysis) -#define _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis)) -#else -#define _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -#endif +# if defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) +# include +# include +# include +# if defined(__APPLE__) +# include +# endif +# if defined(__linux__) +# include +# include +# include +# endif +# endif + +# if defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) +# include +# include +# endif + +# if defined(_LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL) || defined(_LIBCUDACXX_BUILDING_THREAD_LIBRARY_EXTERNAL) +# define _LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_FUNC_VIS +# else +# define _LIBCUDACXX_THREAD_ABI_VISIBILITY inline _LIBCUDACXX_INLINE_VISIBILITY +# endif + +# if defined(__FreeBSD__) && defined(_CCCL_COMPILER_CLANG) && __has_attribute(no_thread_safety_analysis) +# define _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis)) +# else +# define _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS +# endif typedef ::timespec __libcpp_timespec_t; #endif // !defined(_LIBCUDACXX_HAS_NO_THREADS) @@ -76,24 +75,20 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD #if !defined(_LIBCUDACXX_HAS_NO_THREADS) -#define _LIBCUDACXX_POLLING_COUNT 16 +# define _LIBCUDACXX_POLLING_COUNT 16 -_LIBCUDACXX_INLINE_VISIBILITY -inline void __libcpp_thread_yield_processor() +_LIBCUDACXX_INLINE_VISIBILITY inline void __libcpp_thread_yield_processor() { -#if defined(__aarch64__) -# define __LIBCUDACXX_ASM_THREAD_YIELD (asm volatile ("yield" :::);) -#elif defined(__x86_64__) -# define __LIBCUDACXX_ASM_THREAD_YIELD (asm volatile ("pause" :::);) -#elif defined (__powerpc__) -# define __LIBCUDACXX_ASM_THREAD_YIELD (asm volatile ("or 27,27,27":::);) -#else -# define __LIBCUDACXX_ASM_THREAD_YIELD (;) -#endif - NV_IF_TARGET( - NV_IS_HOST, - __LIBCUDACXX_ASM_THREAD_YIELD - ) +# if defined(__aarch64__) +# define __LIBCUDACXX_ASM_THREAD_YIELD (asm volatile("yield" :::);) +# elif defined(__x86_64__) +# define __LIBCUDACXX_ASM_THREAD_YIELD (asm volatile("pause" :::);) +# elif defined(__powerpc__) +# define __LIBCUDACXX_ASM_THREAD_YIELD (asm volatile("or 27,27,27" :::);) +# else +# define __LIBCUDACXX_ASM_THREAD_YIELD (;) +# endif + NV_IF_TARGET(NV_IS_HOST, __LIBCUDACXX_ASM_THREAD_YIELD) } _LIBCUDACXX_THREAD_ABI_VISIBILITY @@ -102,116 +97,114 @@ void __libcpp_thread_yield(); _LIBCUDACXX_THREAD_ABI_VISIBILITY void __libcpp_thread_sleep_for(chrono::nanoseconds __ns); -template -_LIBCUDACXX_THREAD_ABI_VISIBILITY -bool __libcpp_thread_poll_with_backoff(_Fn && __f, chrono::nanoseconds __max = chrono::nanoseconds::zero()); +template +_LIBCUDACXX_THREAD_ABI_VISIBILITY bool +__libcpp_thread_poll_with_backoff(_Fn&& __f, chrono::nanoseconds __max = chrono::nanoseconds::zero()); -#if defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) +# if defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) // Mutex typedef pthread_mutex_t __libcpp_mutex_t; -#define _LIBCUDACXX_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER +# define _LIBCUDACXX_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER typedef pthread_mutex_t __libcpp_recursive_mutex_t; // Condition Variable typedef pthread_cond_t __libcpp_condvar_t; -#define _LIBCUDACXX_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER +# define _LIBCUDACXX_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER // Semaphore -#if defined(__APPLE__) +# if defined(__APPLE__) typedef dispatch_semaphore_t __libcpp_semaphore_t; -# define _LIBCUDACXX_SEMAPHORE_MAX numeric_limits::max() -#else +# define _LIBCUDACXX_SEMAPHORE_MAX numeric_limits::max() +# else typedef sem_t __libcpp_semaphore_t; -# define _LIBCUDACXX_SEMAPHORE_MAX SEM_VALUE_MAX -#endif +# define _LIBCUDACXX_SEMAPHORE_MAX SEM_VALUE_MAX +# endif // Execute once typedef pthread_once_t __libcpp_exec_once_flag; -#define _LIBCUDACXX_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT +# define _LIBCUDACXX_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT // Thread id typedef pthread_t __libcpp_thread_id; // Thread -#define _LIBCUDACXX_NULL_THREAD 0U +# define _LIBCUDACXX_NULL_THREAD 0U typedef pthread_t __libcpp_thread_t; // Thread Local Storage typedef pthread_key_t __libcpp_tls_key; -#define _LIBCUDACXX_TLS_DESTRUCTOR_CC -#elif !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +# define _LIBCUDACXX_TLS_DESTRUCTOR_CC +# elif !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) // Mutex typedef void* __libcpp_mutex_t; -#define _LIBCUDACXX_MUTEX_INITIALIZER 0 +# define _LIBCUDACXX_MUTEX_INITIALIZER 0 -#if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__) +# if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__) typedef void* __libcpp_recursive_mutex_t[6]; -#elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__) +# elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__) typedef void* __libcpp_recursive_mutex_t[5]; -#else -# error Unsupported architecture -#endif +# else +# error Unsupported architecture +# endif // Condition Variable typedef void* __libcpp_condvar_t; -#define _LIBCUDACXX_CONDVAR_INITIALIZER 0 +# define _LIBCUDACXX_CONDVAR_INITIALIZER 0 // Semaphore typedef void* __libcpp_semaphore_t; // Execute Once typedef void* __libcpp_exec_once_flag; -#define _LIBCUDACXX_EXEC_ONCE_INITIALIZER 0 +# define _LIBCUDACXX_EXEC_ONCE_INITIALIZER 0 // Thread ID typedef long __libcpp_thread_id; // Thread -#define _LIBCUDACXX_NULL_THREAD 0U +# define _LIBCUDACXX_NULL_THREAD 0U typedef void* __libcpp_thread_t; // Thread Local Storage typedef long __libcpp_tls_key; -#define _LIBCUDACXX_TLS_DESTRUCTOR_CC __stdcall -#endif // !defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) && !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +# define _LIBCUDACXX_TLS_DESTRUCTOR_CC __stdcall +# endif // !defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) && !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) -#if !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +# if !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) _LIBCUDACXX_THREAD_ABI_VISIBILITY __libcpp_timespec_t __libcpp_to_timespec(const chrono::nanoseconds& __ns); // Mutex _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m); +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t* __m); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS int +__libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t* __m); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS bool +__libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t* __m); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS int +__libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t* __m); _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m); +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t* __m); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -int __libcpp_mutex_lock(__libcpp_mutex_t *__m); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_lock(__libcpp_mutex_t* __m); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS bool +__libcpp_mutex_trylock(__libcpp_mutex_t* __m); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -int __libcpp_mutex_unlock(__libcpp_mutex_t *__m); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS int __libcpp_mutex_unlock(__libcpp_mutex_t* __m); _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_mutex_destroy(__libcpp_mutex_t *__m); +int __libcpp_mutex_destroy(__libcpp_mutex_t* __m); // Condition variable _LIBCUDACXX_THREAD_ABI_VISIBILITY @@ -220,12 +213,11 @@ int __libcpp_condvar_signal(__libcpp_condvar_t* __cv); _LIBCUDACXX_THREAD_ABI_VISIBILITY int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS int +__libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m); -_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS -int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, - __libcpp_timespec_t *__ts); +_LIBCUDACXX_THREAD_ABI_VISIBILITY _LIBCUDACXX_NO_THREAD_SAFETY_ANALYSIS int +__libcpp_condvar_timedwait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m, __libcpp_timespec_t* __ts); _LIBCUDACXX_THREAD_ABI_VISIBILITY int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv); @@ -248,8 +240,7 @@ bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseco // Execute once _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_execute_once(__libcpp_exec_once_flag *flag, - void (*init_routine)()); +int __libcpp_execute_once(__libcpp_exec_once_flag* flag, void (*init_routine)()); // Thread id _LIBCUDACXX_THREAD_ABI_VISIBILITY @@ -260,40 +251,38 @@ bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2); // Thread _LIBCUDACXX_THREAD_ABI_VISIBILITY -bool __libcpp_thread_isnull(const __libcpp_thread_t *__t); +bool __libcpp_thread_isnull(const __libcpp_thread_t* __t); _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), - void *__arg); +int __libcpp_thread_create(__libcpp_thread_t* __t, void* (*__func)(void*), void* __arg); _LIBCUDACXX_THREAD_ABI_VISIBILITY __libcpp_thread_id __libcpp_thread_get_current_id(); _LIBCUDACXX_THREAD_ABI_VISIBILITY -__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t); +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t* __t); _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_thread_join(__libcpp_thread_t *__t); +int __libcpp_thread_join(__libcpp_thread_t* __t); _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_thread_detach(__libcpp_thread_t *__t); +int __libcpp_thread_detach(__libcpp_thread_t* __t); // Thread local storage _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_tls_create(__libcpp_tls_key* __key, - void(_LIBCUDACXX_TLS_DESTRUCTOR_CC* __at_exit)(void*)); +int __libcpp_tls_create(__libcpp_tls_key* __key, void(_LIBCUDACXX_TLS_DESTRUCTOR_CC* __at_exit)(void*)); _LIBCUDACXX_THREAD_ABI_VISIBILITY -void *__libcpp_tls_get(__libcpp_tls_key __key); +void* __libcpp_tls_get(__libcpp_tls_key __key); _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_tls_set(__libcpp_tls_key __key, void *__p); +int __libcpp_tls_set(__libcpp_tls_key __key, void* __p); -#endif // !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) +# endif // !defined(_LIBCUDACXX_HAS_THREAD_API_EXTERNAL) -#if !defined(_LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL) || defined(_LIBCUDACXX_BUILDING_THREAD_LIBRARY_EXTERNAL) +# if !defined(_LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL) || defined(_LIBCUDACXX_BUILDING_THREAD_LIBRARY_EXTERNAL) -#if defined(_LIBCUDACXX_HAS_THREAD_API_CUDA) +# if defined(_LIBCUDACXX_HAS_THREAD_API_CUDA) _LIBCUDACXX_THREAD_ABI_VISIBILITY void __libcpp_thread_yield() {} @@ -301,214 +290,215 @@ void __libcpp_thread_yield() {} _LIBCUDACXX_THREAD_ABI_VISIBILITY void __libcpp_thread_sleep_for(chrono::nanoseconds __ns) { - NV_IF_TARGET( - NV_IS_DEVICE, ( - auto const __step = __ns.count(); - assert(__step < numeric_limits::max()); - asm volatile("nanosleep.u32 %0;"::"r"((unsigned)__step):); - ) - ) + NV_IF_TARGET(NV_IS_DEVICE, + (auto const __step = __ns.count(); assert(__step < numeric_limits::max()); + asm volatile("nanosleep.u32 %0;" ::"r"((unsigned) __step) + :);)) } -#elif defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) +# elif defined(_LIBCUDACXX_HAS_THREAD_API_PTHREAD) _LIBCUDACXX_THREAD_ABI_VISIBILITY __libcpp_timespec_t __libcpp_to_timespec(const chrono::nanoseconds& __ns) { - using namespace chrono; - seconds __s = duration_cast(__ns); - __libcpp_timespec_t __ts; - typedef decltype(__ts.tv_sec) ts_sec; - constexpr ts_sec __ts_sec_max = numeric_limits::max(); - - if (__s.count() < __ts_sec_max) - { - __ts.tv_sec = static_cast(__s.count()); - __ts.tv_nsec = static_cast((__ns - __s).count()); - } - else - { - __ts.tv_sec = __ts_sec_max; - __ts.tv_nsec = 999999999; // (10^9 - 1) - } - return __ts; -} - -_LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) -{ - pthread_mutexattr_t attr; - int __ec = pthread_mutexattr_init(&attr); - if (__ec) - return __ec; - __ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - if (__ec) { - pthread_mutexattr_destroy(&attr); - return __ec; - } - __ec = pthread_mutex_init(__m, &attr); - if (__ec) { - pthread_mutexattr_destroy(&attr); - return __ec; - } - __ec = pthread_mutexattr_destroy(&attr); - if (__ec) { - pthread_mutex_destroy(__m); - return __ec; - } - return 0; + using namespace chrono; + seconds __s = duration_cast(__ns); + __libcpp_timespec_t __ts; + typedef decltype(__ts.tv_sec) ts_sec; + constexpr ts_sec __ts_sec_max = numeric_limits::max(); + + if (__s.count() < __ts_sec_max) + { + __ts.tv_sec = static_cast(__s.count()); + __ts.tv_nsec = static_cast((__ns - __s).count()); + } + else + { + __ts.tv_sec = __ts_sec_max; + __ts.tv_nsec = 999999999; // (10^9 - 1) + } + return __ts; } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t* __m) { - return pthread_mutex_lock(__m); + pthread_mutexattr_t attr; + int __ec = pthread_mutexattr_init(&attr); + if (__ec) + { + return __ec; + } + __ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + if (__ec) + { + pthread_mutexattr_destroy(&attr); + return __ec; + } + __ec = pthread_mutex_init(__m, &attr); + if (__ec) + { + pthread_mutexattr_destroy(&attr); + return __ec; + } + __ec = pthread_mutexattr_destroy(&attr); + if (__ec) + { + pthread_mutex_destroy(__m); + return __ec; + } + return 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY -bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t* __m) { - return pthread_mutex_trylock(__m) == 0; + return pthread_mutex_lock(__m); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_unlock(__libcpp_mutex_t *__m) +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t* __m) { - return pthread_mutex_unlock(__m); + return pthread_mutex_trylock(__m) == 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m) +int __libcpp_recursive_mutex_unlock(__libcpp_mutex_t* __m) { - return pthread_mutex_destroy(__m); + return pthread_mutex_unlock(__m); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_mutex_lock(__libcpp_mutex_t *__m) +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t* __m) { - return pthread_mutex_lock(__m); + return pthread_mutex_destroy(__m); +} + +_LIBCUDACXX_THREAD_ABI_VISIBILITY +int __libcpp_mutex_lock(__libcpp_mutex_t* __m) +{ + return pthread_mutex_lock(__m); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) +bool __libcpp_mutex_trylock(__libcpp_mutex_t* __m) { - return pthread_mutex_trylock(__m) == 0; + return pthread_mutex_trylock(__m) == 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) +int __libcpp_mutex_unlock(__libcpp_mutex_t* __m) { - return pthread_mutex_unlock(__m); + return pthread_mutex_unlock(__m); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) +int __libcpp_mutex_destroy(__libcpp_mutex_t* __m) { return pthread_mutex_destroy(__m); } // Condition Variable _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_condvar_signal(__libcpp_condvar_t *__cv) +int __libcpp_condvar_signal(__libcpp_condvar_t* __cv) { - return pthread_cond_signal(__cv); + return pthread_cond_signal(__cv); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv) +int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv) { - return pthread_cond_broadcast(__cv); + return pthread_cond_broadcast(__cv); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) +int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m) { - return pthread_cond_wait(__cv, __m); + return pthread_cond_wait(__cv, __m); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, - __libcpp_timespec_t *__ts) +int __libcpp_condvar_timedwait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m, __libcpp_timespec_t* __ts) { - return pthread_cond_timedwait(__cv, __m, __ts); + return pthread_cond_timedwait(__cv, __m, __ts); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) +int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv) { - return pthread_cond_destroy(__cv); + return pthread_cond_destroy(__cv); } // Semaphore -#if defined(__APPLE__) +# if defined(__APPLE__) bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init) { - return (*__sem = dispatch_semaphore_create(__init)) != NULL; + return (*__sem = dispatch_semaphore_create(__init)) != NULL; } bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem) { - dispatch_release(*__sem); - return true; + dispatch_release(*__sem); + return true; } bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem) { - dispatch_semaphore_signal(*__sem); - return true; + dispatch_semaphore_signal(*__sem); + return true; } bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem) { - return dispatch_semaphore_wait(*__sem, DISPATCH_TIME_FOREVER) == 0; + return dispatch_semaphore_wait(*__sem, DISPATCH_TIME_FOREVER) == 0; } bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns) { - return dispatch_semaphore_wait(*__sem, dispatch_time(DISPATCH_TIME_NOW, __ns.count())) == 0; + return dispatch_semaphore_wait(*__sem, dispatch_time(DISPATCH_TIME_NOW, __ns.count())) == 0; } -#else +# else _LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_semaphore_init(__libcpp_semaphore_t* __sem, int __init) { - return sem_init(__sem, 0, __init) == 0; + return sem_init(__sem, 0, __init) == 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_semaphore_destroy(__libcpp_semaphore_t* __sem) { - return sem_destroy(__sem) == 0; + return sem_destroy(__sem) == 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_semaphore_post(__libcpp_semaphore_t* __sem) { - return sem_post(__sem) == 0; + return sem_post(__sem) == 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_semaphore_wait(__libcpp_semaphore_t* __sem) { - return sem_wait(__sem) == 0; + return sem_wait(__sem) == 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_semaphore_wait_timed(__libcpp_semaphore_t* __sem, chrono::nanoseconds const& __ns) { - __libcpp_timespec_t __ts = __libcpp_to_timespec(__ns); - return sem_timedwait(__sem, &__ts) == 0; + __libcpp_timespec_t __ts = __libcpp_to_timespec(__ns); + return sem_timedwait(__sem, &__ts) == 0; } -#endif //__APPLE__ +# endif //__APPLE__ // Execute once _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_execute_once(__libcpp_exec_once_flag *flag, void (*init_routine)()) +int __libcpp_execute_once(__libcpp_exec_once_flag* flag, void (*init_routine)()) { - return pthread_once(flag, init_routine); + return pthread_once(flag, init_routine); } // Thread id @@ -516,183 +506,200 @@ int __libcpp_execute_once(__libcpp_exec_once_flag *flag, void (*init_routine)()) _LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2) { - return pthread_equal(t1, t2) != 0; + return pthread_equal(t1, t2) != 0; } // Returns non-zero if t1 < t2, otherwise 0 _LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2) { - return t1 < t2; + return t1 < t2; } // Thread _LIBCUDACXX_THREAD_ABI_VISIBILITY -bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) +bool __libcpp_thread_isnull(const __libcpp_thread_t* __t) { - return *__t == 0; + return *__t == 0; } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), - void *__arg) +int __libcpp_thread_create(__libcpp_thread_t* __t, void* (*__func)(void*), void* __arg) { - return pthread_create(__t, 0, __func, __arg); + return pthread_create(__t, 0, __func, __arg); } _LIBCUDACXX_THREAD_ABI_VISIBILITY __libcpp_thread_id __libcpp_thread_get_current_id() { - return pthread_self(); + return pthread_self(); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t* __t) { - return *__t; + return *__t; } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_thread_join(__libcpp_thread_t *__t) +int __libcpp_thread_join(__libcpp_thread_t* __t) { - return pthread_join(*__t, 0); + return pthread_join(*__t, 0); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_thread_detach(__libcpp_thread_t *__t) +int __libcpp_thread_detach(__libcpp_thread_t* __t) { - return pthread_detach(*__t); + return pthread_detach(*__t); } // Thread local storage _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *)) +int __libcpp_tls_create(__libcpp_tls_key* __key, void (*__at_exit)(void*)) { - return pthread_key_create(__key, __at_exit); + return pthread_key_create(__key, __at_exit); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -void *__libcpp_tls_get(__libcpp_tls_key __key) +void* __libcpp_tls_get(__libcpp_tls_key __key) { - return pthread_getspecific(__key); + return pthread_getspecific(__key); } _LIBCUDACXX_THREAD_ABI_VISIBILITY -int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) +int __libcpp_tls_set(__libcpp_tls_key __key, void* __p) { - return pthread_setspecific(__key, __p); + return pthread_setspecific(__key, __p); } _LIBCUDACXX_THREAD_ABI_VISIBILITY void __libcpp_thread_yield() { - sched_yield(); + sched_yield(); } _LIBCUDACXX_THREAD_ABI_VISIBILITY void __libcpp_thread_sleep_for(chrono::nanoseconds __ns) { - __libcpp_timespec_t __ts = __libcpp_to_timespec(__ns); - while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR); + __libcpp_timespec_t __ts = __libcpp_to_timespec(__ns); + while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR) + ; } -#if defined(__linux__) && !defined(_LIBCUDACXX_HAS_NO_PLATFORM_WAIT) +# if defined(__linux__) && !defined(_LIBCUDACXX_HAS_NO_PLATFORM_WAIT) -#define _LIBCUDACXX_HAS_PLATFORM_WAIT +# define _LIBCUDACXX_HAS_PLATFORM_WAIT typedef int __libcpp_platform_wait_t; -template -struct __libcpp_platform_wait_uses_type { - enum { __value = is_same<__remove_cv_t<_Tp>, __libcpp_platform_wait_t>::value }; +template +struct __libcpp_platform_wait_uses_type +{ + enum + { + __value = is_same<__remove_cv_t<_Tp>, __libcpp_platform_wait_t>::value + }; }; template ::__value, int>::type = 1> -void __libcpp_platform_wait(_Tp const* ptr, _Tp val, void const* timeout) { - syscall(SYS_futex, ptr, FUTEX_WAIT_PRIVATE, val, timeout, 0, 0); +void __libcpp_platform_wait(_Tp const* ptr, _Tp val, void const* timeout) +{ + syscall(SYS_futex, ptr, FUTEX_WAIT_PRIVATE, val, timeout, 0, 0); } template ::__value, int>::type = 1> -void __libcpp_platform_wake(_Tp const* ptr, bool all) { - syscall(SYS_futex, ptr, FUTEX_WAKE_PRIVATE, all ? INT_MAX : 1, 0, 0, 0); +void __libcpp_platform_wake(_Tp const* ptr, bool all) +{ + syscall(SYS_futex, ptr, FUTEX_WAKE_PRIVATE, all ? INT_MAX : 1, 0, 0, 0); } -#endif // defined(__linux__) && !defined(_LIBCUDACXX_HAS_NO_PLATFORM_WAIT) +# endif // defined(__linux__) && !defined(_LIBCUDACXX_HAS_NO_PLATFORM_WAIT) -#elif defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) +# elif defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) void __libcpp_thread_yield() { - SwitchToThread(); + SwitchToThread(); } void __libcpp_thread_sleep_for(chrono::nanoseconds __ns) { - using namespace chrono; - // round-up to the nearest milisecond - milliseconds __ms = - duration_cast(__ns + chrono::nanoseconds(999999)); - Sleep(static_cast(__ms.count())); + using namespace chrono; + // round-up to the nearest milisecond + milliseconds __ms = duration_cast(__ns + chrono::nanoseconds(999999)); + Sleep(static_cast(__ms.count())); } -#endif // defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) +# endif // defined(_LIBCUDACXX_HAS_THREAD_API_WIN32) -#endif // !defined(_LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL) || defined(_LIBCUDACXX_BUILDING_THREAD_LIBRARY_EXTERNAL) +# endif // !defined(_LIBCUDACXX_HAS_THREAD_LIBRARY_EXTERNAL) || defined(_LIBCUDACXX_BUILDING_THREAD_LIBRARY_EXTERNAL) -template -_LIBCUDACXX_THREAD_ABI_VISIBILITY -bool __libcpp_thread_poll_with_backoff(_Fn && __f, chrono::nanoseconds __max) +template +_LIBCUDACXX_THREAD_ABI_VISIBILITY bool __libcpp_thread_poll_with_backoff(_Fn&& __f, chrono::nanoseconds __max) { - chrono::high_resolution_clock::time_point const __start = chrono::high_resolution_clock::now(); - for(int __count = 0;;) { - if(__f()) - return true; - if(__count < _LIBCUDACXX_POLLING_COUNT) { - if(__count > (_LIBCUDACXX_POLLING_COUNT >> 1)) - __libcpp_thread_yield_processor(); - __count += 1; - continue; + chrono::high_resolution_clock::time_point const __start = chrono::high_resolution_clock::now(); + for (int __count = 0;;) + { + if (__f()) + { + return true; + } + if (__count < _LIBCUDACXX_POLLING_COUNT) + { + if (__count > (_LIBCUDACXX_POLLING_COUNT >> 1)) + { + __libcpp_thread_yield_processor(); } - chrono::high_resolution_clock::duration const __elapsed = chrono::high_resolution_clock::now() - __start; - if(__max != chrono::nanoseconds::zero() && - __max < __elapsed) - return false; - chrono::nanoseconds const __step = __elapsed / 4; - if(__step >= chrono::milliseconds(1)) - __libcpp_thread_sleep_for(chrono::milliseconds(1)); - else if(__step >= chrono::microseconds(10)) - __libcpp_thread_sleep_for(__step); - else - __libcpp_thread_yield(); + __count += 1; + continue; + } + chrono::high_resolution_clock::duration const __elapsed = chrono::high_resolution_clock::now() - __start; + if (__max != chrono::nanoseconds::zero() && __max < __elapsed) + { + return false; + } + chrono::nanoseconds const __step = __elapsed / 4; + if (__step >= chrono::milliseconds(1)) + { + __libcpp_thread_sleep_for(chrono::milliseconds(1)); + } + else if (__step >= chrono::microseconds(10)) + { + __libcpp_thread_sleep_for(__step); } + else + { + __libcpp_thread_yield(); + } + } } -#ifndef _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE +# ifndef _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE -struct alignas(64) __libcpp_contention_t { -#if defined(_LIBCUDACXX_HAS_PLATFORM_WAIT) - ptrdiff_t __waiters = 0; - __libcpp_platform_wait_t __version = 0; -#else - ptrdiff_t __credit = 0; - __libcpp_mutex_t __mutex = _LIBCUDACXX_MUTEX_INITIALIZER; - __libcpp_condvar_t __condvar = _LIBCUDACXX_CONDVAR_INITIALIZER; -#endif +struct alignas(64) __libcpp_contention_t +{ +# if defined(_LIBCUDACXX_HAS_PLATFORM_WAIT) + ptrdiff_t __waiters = 0; + __libcpp_platform_wait_t __version = 0; +# else + ptrdiff_t __credit = 0; + __libcpp_mutex_t __mutex = _LIBCUDACXX_MUTEX_INITIALIZER; + __libcpp_condvar_t __condvar = _LIBCUDACXX_CONDVAR_INITIALIZER; +# endif }; _LIBCUDACXX_FUNC_VIS -__libcpp_contention_t * __libcpp_contention_state(void const volatile * p) noexcept; +__libcpp_contention_t* __libcpp_contention_state(void const volatile* p) noexcept; -#endif // _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE +# endif // _LIBCUDACXX_HAS_NO_THREAD_CONTENTION_TABLE -#if !defined(_LIBCUDACXX_HAS_NO_TREE_BARRIER) && !defined(_LIBCUDACXX_HAS_NO_THREAD_FAVORITE_BARRIER_INDEX) +# if !defined(_LIBCUDACXX_HAS_NO_TREE_BARRIER) && !defined(_LIBCUDACXX_HAS_NO_THREAD_FAVORITE_BARRIER_INDEX) -_LIBCUDACXX_EXPORTED_FROM_ABI -extern thread_local ptrdiff_t __libcpp_thread_favorite_barrier_index; +_LIBCUDACXX_EXPORTED_FROM_ABI extern thread_local ptrdiff_t __libcpp_thread_favorite_barrier_index; -#endif +# endif -#ifndef __cuda_std__ +# ifndef __cuda_std__ class _LIBCUDACXX_TYPE_VIS thread; class _LIBCUDACXX_TYPE_VIS __thread_id; @@ -702,81 +709,96 @@ namespace this_thread _LIBCUDACXX_INLINE_VISIBILITY __thread_id get_id() noexcept; -} // this_thread +} // namespace this_thread -template<> struct hash<__thread_id>; +template <> +struct hash<__thread_id>; class _LIBCUDACXX_TEMPLATE_VIS __thread_id { - // FIXME: pthread_t is a pointer on Darwin but a long on Linux. - // NULL is the no-thread value on Darwin. Someone needs to check - // on other platforms. We assume 0 works everywhere for now. - __libcpp_thread_id __id_; + // FIXME: pthread_t is a pointer on Darwin but a long on Linux. + // NULL is the no-thread value on Darwin. Someone needs to check + // on other platforms. We assume 0 works everywhere for now. + __libcpp_thread_id __id_; public: - _LIBCUDACXX_INLINE_VISIBILITY - __thread_id() noexcept : __id_(0) {} - - friend _LIBCUDACXX_INLINE_VISIBILITY - bool operator==(__thread_id __x, __thread_id __y) noexcept - { // don't pass id==0 to underlying routines - if (__x.__id_ == 0) return __y.__id_ == 0; - if (__y.__id_ == 0) return false; - return __libcpp_thread_id_equal(__x.__id_, __y.__id_); - } - friend _LIBCUDACXX_INLINE_VISIBILITY - bool operator!=(__thread_id __x, __thread_id __y) noexcept - {return !(__x == __y);} - friend _LIBCUDACXX_INLINE_VISIBILITY - bool operator< (__thread_id __x, __thread_id __y) noexcept - { // id==0 is always less than any other thread_id - if (__x.__id_ == 0) return __y.__id_ != 0; - if (__y.__id_ == 0) return false; - return __libcpp_thread_id_less(__x.__id_, __y.__id_); - } - friend _LIBCUDACXX_INLINE_VISIBILITY - bool operator<=(__thread_id __x, __thread_id __y) noexcept - {return !(__y < __x);} - friend _LIBCUDACXX_INLINE_VISIBILITY - bool operator> (__thread_id __x, __thread_id __y) noexcept - {return __y < __x ;} - friend _LIBCUDACXX_INLINE_VISIBILITY - bool operator>=(__thread_id __x, __thread_id __y) noexcept - {return !(__x < __y);} - - _LIBCUDACXX_INLINE_VISIBILITY - void __reset() { __id_ = 0; } - -#ifndef __cuda_std__ - template - friend - _LIBCUDACXX_INLINE_VISIBILITY - basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id); -#endif + _LIBCUDACXX_INLINE_VISIBILITY __thread_id() noexcept + : __id_(0) + {} + + friend _LIBCUDACXX_INLINE_VISIBILITY bool operator==(__thread_id __x, __thread_id __y) noexcept + { // don't pass id==0 to underlying routines + if (__x.__id_ == 0) + { + return __y.__id_ == 0; + } + if (__y.__id_ == 0) + { + return false; + } + return __libcpp_thread_id_equal(__x.__id_, __y.__id_); + } + friend _LIBCUDACXX_INLINE_VISIBILITY bool operator!=(__thread_id __x, __thread_id __y) noexcept + { + return !(__x == __y); + } + friend _LIBCUDACXX_INLINE_VISIBILITY bool operator<(__thread_id __x, __thread_id __y) noexcept + { // id==0 is always less than any other thread_id + if (__x.__id_ == 0) + { + return __y.__id_ != 0; + } + if (__y.__id_ == 0) + { + return false; + } + return __libcpp_thread_id_less(__x.__id_, __y.__id_); + } + friend _LIBCUDACXX_INLINE_VISIBILITY bool operator<=(__thread_id __x, __thread_id __y) noexcept + { + return !(__y < __x); + } + friend _LIBCUDACXX_INLINE_VISIBILITY bool operator>(__thread_id __x, __thread_id __y) noexcept + { + return __y < __x; + } + friend _LIBCUDACXX_INLINE_VISIBILITY bool operator>=(__thread_id __x, __thread_id __y) noexcept + { + return !(__x < __y); + } + + _LIBCUDACXX_INLINE_VISIBILITY void __reset() + { + __id_ = 0; + } + +# ifndef __cuda_std__ + template + friend _LIBCUDACXX_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id); +# endif private: - _LIBCUDACXX_INLINE_VISIBILITY - __thread_id(__libcpp_thread_id __id) : __id_(__id) {} + _LIBCUDACXX_INLINE_VISIBILITY __thread_id(__libcpp_thread_id __id) + : __id_(__id) + {} - friend __thread_id this_thread::get_id() noexcept; - friend class _LIBCUDACXX_TYPE_VIS thread; - friend struct _LIBCUDACXX_TEMPLATE_VIS hash<__thread_id>; + friend __thread_id this_thread::get_id() noexcept; + friend class _LIBCUDACXX_TYPE_VIS thread; + friend struct _LIBCUDACXX_TEMPLATE_VIS hash<__thread_id>; }; namespace this_thread { -inline _LIBCUDACXX_INLINE_VISIBILITY -__thread_id -get_id() noexcept +inline _LIBCUDACXX_INLINE_VISIBILITY __thread_id get_id() noexcept { - return __libcpp_thread_get_current_id(); + return __libcpp_thread_get_current_id(); } -} // this_thread +} // namespace this_thread -#endif // __cuda_std__ +# endif // __cuda_std__ #endif // !_LIBCUDACXX_HAS_NO_THREADS diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/__undef_macros b/libcudacxx/include/cuda/std/detail/libcxx/include/__undef_macros index 37594493df2..817a2b97116 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/__undef_macros +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/__undef_macros @@ -7,27 +7,26 @@ // //===----------------------------------------------------------------------===// - #ifdef min -#if !defined(_LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS) -#if defined(_LIBCUDACXX_WARNING) +# if !defined(_LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS) +# if defined(_LIBCUDACXX_WARNING) _LIBCUDACXX_WARNING("macro min is incompatible with C++. Try #define NOMINMAX " - "before any Windows header. #undefing min") -#else -#warning: macro min is incompatible with C++. #undefing min -#endif -#endif -#undef min + "before any Windows header. #undefing min") +# else +# warning : macro min is incompatible with C++. #undefing min +# endif +# endif +# undef min #endif #ifdef max -#if !defined(_LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS) -#if defined(_LIBCUDACXX_WARNING) +# if !defined(_LIBCUDACXX_DISABLE_MACRO_CONFLICT_WARNINGS) +# if defined(_LIBCUDACXX_WARNING) _LIBCUDACXX_WARNING("macro max is incompatible with C++. Try #define NOMINMAX " - "before any Windows header. #undefing max") -#else -#warning: macro max is incompatible with C++. #undefing max -#endif -#endif -#undef max + "before any Windows header. #undefing max") +# else +# warning : macro max is incompatible with C++. #undefing max +# endif +# endif +# undef max #endif diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/__verbose_abort b/libcudacxx/include/cuda/std/detail/libcxx/include/__verbose_abort index afb61ecc8cd..cfc433c561b 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/__verbose_abort +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/__verbose_abort @@ -29,14 +29,16 @@ // // We can't provide a great implementation because it needs to be pretty much // dependency-free (this is included everywhere else in the library). -#if defined(_LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY) && !defined(_LIBCUDACXX_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED) +#if defined(_LIBCUDACXX_HAS_NO_VERBOSE_ABORT_IN_LIBRARY) \ + && !defined(_LIBCUDACXX_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED) extern "C" void abort(); _LIBCUDACXX_BEGIN_NAMESPACE_STD -_CCCL_NORETURN _LIBCUDACXX_ATTRIBUTE_FORMAT(__printf__, 1, 2) _LIBCUDACXX_HIDE_FROM_ABI inline -void __libcpp_verbose_abort(const char *, ...) { +_CCCL_NORETURN _LIBCUDACXX_ATTRIBUTE_FORMAT(__printf__, 1, 2) + _LIBCUDACXX_HIDE_FROM_ABI inline void __libcpp_verbose_abort(const char*, ...) +{ ::abort(); __builtin_unreachable(); // never reached, but needed to tell the compiler that the function never returns } @@ -47,8 +49,8 @@ _LIBCUDACXX_END_NAMESPACE_STD _LIBCUDACXX_BEGIN_NAMESPACE_STD -_CCCL_NORETURN _LIBCUDACXX_OVERRIDABLE_FUNC_VIS _LIBCUDACXX_ATTRIBUTE_FORMAT(__printf__, 1, 2) -void __libcpp_verbose_abort(const char *__format, ...); +_CCCL_NORETURN _LIBCUDACXX_OVERRIDABLE_FUNC_VIS + _LIBCUDACXX_ATTRIBUTE_FORMAT(__printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...); _LIBCUDACXX_END_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/algorithm b/libcudacxx/include/cuda/std/detail/libcxx/include/algorithm index 78c168c8bfd..780d8f9362b 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/algorithm +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/algorithm @@ -645,83 +645,81 @@ template # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler -#include #include #include #include #include #include -#include #include +#include +#include #include #include #include -#include -#include #include -#include +#include #include -#include +#include #include +#include +#include #include #include -#include #include -#include -#include +#include #include -#include +#include #include +#include #include #include -#include #include +#include #include #include -#include #include +#include #include #include #include #include #include #include -#include #include +#include #include -#include #include -#include +#include #include +#include #include -#include #include +#include #include #include -#include #include +#include +#include #include #include -#include #include #include #include #include -#include +#include #include +#include #include -#include -#include +#include #include +#include #include -#include -#include #include -#include +#include #include -#include +#include #include +#include #include #include #include @@ -732,8 +730,8 @@ template #include #include #include -#include #include +#include #include #include #include @@ -751,9 +749,11 @@ template #include #include #include -#include #include #include +#include // all public C++ headers provide the assertion handler +#include +#include #include #include #include @@ -769,20 +769,26 @@ template class __invert // invert the sense of a comparison { private: - _Predicate __p_; + _Predicate __p_; + public: - _LIBCUDACXX_INLINE_VISIBILITY __invert() {} + _LIBCUDACXX_INLINE_VISIBILITY __invert() {} - _LIBCUDACXX_INLINE_VISIBILITY - explicit __invert(_Predicate __p) : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __invert(_Predicate __p) + : __p_(__p) + {} - template - _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _T1& __x) {return !__p_(__x);} + template + _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _T1& __x) + { + return !__p_(__x); + } - template - _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);} + template + _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) + { + return __p_(__y, __x); + } }; // random_shuffle @@ -792,275 +798,335 @@ public: template struct __log2_imp { - static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp - : __log2_imp<_Xp, _Rp - 1>::value; + static const size_t value = _Xp & ((unsigned long long) (1) << _Rp) ? _Rp : __log2_imp<_Xp, _Rp - 1>::value; }; template struct __log2_imp<_Xp, 0> { - static const size_t value = 0; + static const size_t value = 0; }; template struct __log2_imp<0, _Rp> { - static const size_t value = _Rp + 1; + static const size_t value = _Rp + 1; }; template struct __log2 { - static const size_t value = __log2_imp<_Xp, - sizeof(_UIntType) * __CHAR_BIT__ - 1>::value; + static const size_t value = __log2_imp<_Xp, sizeof(_UIntType) * __CHAR_BIT__ - 1>::value; }; -template +template class __independent_bits_engine { public: - // types - typedef _UIntType result_type; + // types + typedef _UIntType result_type; private: - typedef typename _Engine::result_type _Engine_result_type; - typedef __conditional_t - < - sizeof(_Engine_result_type) <= sizeof(result_type), - result_type, - _Engine_result_type - > _Working_result_type; - - _Engine& __e_; - size_t __w_; - size_t __w0_; - size_t __n_; - size_t __n0_; - _Working_result_type __y0_; - _Working_result_type __y1_; - _Engine_result_type __mask0_; - _Engine_result_type __mask1_; - - static constexpr _Working_result_type _Rp = - _Engine::max() - _Engine::min() + _Working_result_type(1); - static constexpr size_t __m = __log2<_Working_result_type, _Rp>::value; - static constexpr size_t _WDt = numeric_limits<_Working_result_type>::digits; - static constexpr size_t _EDt = numeric_limits<_Engine_result_type>::digits; + typedef typename _Engine::result_type _Engine_result_type; + typedef __conditional_t + _Working_result_type; + + _Engine& __e_; + size_t __w_; + size_t __w0_; + size_t __n_; + size_t __n0_; + _Working_result_type __y0_; + _Working_result_type __y1_; + _Engine_result_type __mask0_; + _Engine_result_type __mask1_; + + static constexpr _Working_result_type _Rp = _Engine::max() - _Engine::min() + _Working_result_type(1); + static constexpr size_t __m = __log2<_Working_result_type, _Rp>::value; + static constexpr size_t _WDt = numeric_limits<_Working_result_type>::digits; + static constexpr size_t _EDt = numeric_limits<_Engine_result_type>::digits; public: - // constructors and seeding functions - __independent_bits_engine(_Engine& __e, size_t __w); + // constructors and seeding functions + __independent_bits_engine(_Engine& __e, size_t __w); - // generating functions - result_type operator()() {return __eval(integral_constant());} + // generating functions + result_type operator()() + { + return __eval(integral_constant()); + } private: - result_type __eval(false_type); - result_type __eval(true_type); + result_type __eval(false_type); + result_type __eval(true_type); }; -template -__independent_bits_engine<_Engine, _UIntType> - ::__independent_bits_engine(_Engine& __e, size_t __w) - : __e_(__e), - __w_(__w) +template +__independent_bits_engine<_Engine, _UIntType>::__independent_bits_engine(_Engine& __e, size_t __w) + : __e_(__e) + , __w_(__w) { - __n_ = __w_ / __m + (__w_ % __m != 0); + __n_ = __w_ / __m + (__w_ % __m != 0); + __w0_ = __w_ / __n_; + if (_Rp == 0) + { + __y0_ = _Rp; + } + else if (__w0_ < _WDt) + { + __y0_ = (_Rp >> __w0_) << __w0_; + } + else + { + __y0_ = 0; + } + if (_Rp - __y0_ > __y0_ / __n_) + { + ++__n_; __w0_ = __w_ / __n_; - if (_Rp == 0) - __y0_ = _Rp; - else if (__w0_ < _WDt) - __y0_ = (_Rp >> __w0_) << __w0_; - else - __y0_ = 0; - if (_Rp - __y0_ > __y0_ / __n_) - { - ++__n_; - __w0_ = __w_ / __n_; - if (__w0_ < _WDt) - __y0_ = (_Rp >> __w0_) << __w0_; - else - __y0_ = 0; - } - __n0_ = __n_ - __w_ % __n_; - if (__w0_ < _WDt - 1) - __y1_ = (_Rp >> (__w0_ + 1)) << (__w0_ + 1); + if (__w0_ < _WDt) + { + __y0_ = (_Rp >> __w0_) << __w0_; + } else - __y1_ = 0; - __mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) : - _Engine_result_type(0); - __mask1_ = __w0_ < _EDt - 1 ? - _Engine_result_type(~0) >> (_EDt - (__w0_ + 1)) : - _Engine_result_type(~0); + { + __y0_ = 0; + } + } + __n0_ = __n_ - __w_ % __n_; + if (__w0_ < _WDt - 1) + { + __y1_ = (_Rp >> (__w0_ + 1)) << (__w0_ + 1); + } + else + { + __y1_ = 0; + } + __mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) : _Engine_result_type(0); + __mask1_ = __w0_ < _EDt - 1 ? _Engine_result_type(~0) >> (_EDt - (__w0_ + 1)) : _Engine_result_type(~0); } -template -inline -_UIntType -__independent_bits_engine<_Engine, _UIntType>::__eval(false_type) +template +inline _UIntType __independent_bits_engine<_Engine, _UIntType>::__eval(false_type) { - return static_cast(__e_() & __mask0_); + return static_cast(__e_() & __mask0_); } -template -_UIntType -__independent_bits_engine<_Engine, _UIntType>::__eval(true_type) +template +_UIntType __independent_bits_engine<_Engine, _UIntType>::__eval(true_type) { - const size_t _WRt = numeric_limits::digits; - result_type _Sp = 0; - for (size_t __k = 0; __k < __n0_; ++__k) + const size_t _WRt = numeric_limits::digits; + result_type _Sp = 0; + for (size_t __k = 0; __k < __n0_; ++__k) + { + _Engine_result_type __u; + do { - _Engine_result_type __u; - do - { - __u = __e_() - _Engine::min(); - } while (__u >= __y0_); - if (__w0_ < _WRt) - _Sp <<= __w0_; - else - _Sp = 0; - _Sp += __u & __mask0_; - } - for (size_t __k = __n0_; __k < __n_; ++__k) - { - _Engine_result_type __u; - do - { - __u = __e_() - _Engine::min(); - } while (__u >= __y1_); - if (__w0_ < _WRt - 1) - _Sp <<= __w0_ + 1; - else - _Sp = 0; - _Sp += __u & __mask1_; - } - return _Sp; + __u = __e_() - _Engine::min(); + } while (__u >= __y0_); + if (__w0_ < _WRt) + { + _Sp <<= __w0_; + } + else + { + _Sp = 0; + } + _Sp += __u & __mask0_; + } + for (size_t __k = __n0_; __k < __n_; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y1_); + if (__w0_ < _WRt - 1) + { + _Sp <<= __w0_ + 1; + } + else + { + _Sp = 0; + } + _Sp += __u & __mask1_; + } + return _Sp; } // uniform_int_distribution -template +template class uniform_int_distribution { public: - // types - typedef _IntType result_type; + // types + typedef _IntType result_type; - class param_type - { - result_type __a_; - result_type __b_; - public: - typedef uniform_int_distribution distribution_type; + class param_type + { + result_type __a_; + result_type __b_; + + public: + typedef uniform_int_distribution distribution_type; - explicit param_type(result_type __a = 0, - result_type __b = numeric_limits::max()) - : __a_(__a), __b_(__b) {} + explicit param_type(result_type __a = 0, result_type __b = numeric_limits::max()) + : __a_(__a) + , __b_(__b) + {} - result_type a() const {return __a_;} - result_type b() const {return __b_;} + result_type a() const + { + return __a_; + } + result_type b() const + { + return __b_; + } - friend bool operator==(const param_type& __x, const param_type& __y) - {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} - friend bool operator!=(const param_type& __x, const param_type& __y) - {return !(__x == __y);} - }; + friend bool operator==(const param_type& __x, const param_type& __y) + { + return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_; + } + friend bool operator!=(const param_type& __x, const param_type& __y) + { + return !(__x == __y); + } + }; private: - param_type __p_; + param_type __p_; public: - // constructors and reset functions - explicit uniform_int_distribution(result_type __a = 0, - result_type __b = numeric_limits::max()) - : __p_(param_type(__a, __b)) {} - explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {} - void reset() {} - - // generating functions - template result_type operator()(_URNG& __g) - {return (*this)(__g, __p_);} - template result_type operator()(_URNG& __g, const param_type& __p); - - // property functions - result_type a() const {return __p_.a();} - result_type b() const {return __p_.b();} - - param_type param() const {return __p_;} - void param(const param_type& __p) {__p_ = __p;} - - result_type min() const {return a();} - result_type max() const {return b();} - - friend bool operator==(const uniform_int_distribution& __x, - const uniform_int_distribution& __y) - {return __x.__p_ == __y.__p_;} - friend bool operator!=(const uniform_int_distribution& __x, - const uniform_int_distribution& __y) - {return !(__x == __y);} + // constructors and reset functions + explicit uniform_int_distribution(result_type __a = 0, result_type __b = numeric_limits::max()) + : __p_(param_type(__a, __b)) + {} + explicit uniform_int_distribution(const param_type& __p) + : __p_(__p) + {} + void reset() {} + + // generating functions + template + result_type operator()(_URNG& __g) + { + return (*this)(__g, __p_); + } + template + result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + result_type a() const + { + return __p_.a(); + } + result_type b() const + { + return __p_.b(); + } + + param_type param() const + { + return __p_; + } + void param(const param_type& __p) + { + __p_ = __p; + } + + result_type min() const + { + return a(); + } + result_type max() const + { + return b(); + } + + friend bool operator==(const uniform_int_distribution& __x, const uniform_int_distribution& __y) + { + return __x.__p_ == __y.__p_; + } + friend bool operator!=(const uniform_int_distribution& __x, const uniform_int_distribution& __y) + { + return !(__x == __y); + } }; -template -template -typename uniform_int_distribution<_IntType>::result_type -uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) -_LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +template +template +typename uniform_int_distribution<_IntType>::result_type uniform_int_distribution<_IntType>::operator()( + _URNG& __g, const param_type& __p) _LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { - typedef __conditional_t _UIntType; - const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1); - if (_Rp == 1) - return __p.a(); - const size_t _Dt = numeric_limits<_UIntType>::digits; - typedef __independent_bits_engine<_URNG, _UIntType> _Eng; - if (_Rp == 0) - return static_cast(_Eng(__g, _Dt)()); - size_t __w = _Dt - __libcpp_clz(_Rp) - 1; - if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0) - ++__w; - _Eng __e(__g, __w); - _UIntType __u; - do - { - __u = __e(); - } while (__u >= _Rp); - return static_cast(__u + __p.a()); + typedef __conditional_t _UIntType; + const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1); + if (_Rp == 1) + { + return __p.a(); + } + const size_t _Dt = numeric_limits<_UIntType>::digits; + typedef __independent_bits_engine<_URNG, _UIntType> _Eng; + if (_Rp == 0) + { + return static_cast(_Eng(__g, _Dt)()); + } + size_t __w = _Dt - __libcpp_clz(_Rp) - 1; + if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0) + { + ++__w; + } + _Eng __e(__g, __w); + _UIntType __u; + do + { + __u = __e(); + } while (__u >= _Rp); + return static_cast(__u + __p.a()); } -template -_LIBCUDACXX_INLINE_VISIBILITY -_SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output_iter, - _Distance __n, - _UniformRandomNumberGenerator & __g, - input_iterator_tag) { - +template +_LIBCUDACXX_INLINE_VISIBILITY _SampleIterator __sample( + _PopulationIterator __first, + _PopulationIterator __last, + _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator& __g, + input_iterator_tag) +{ _Distance __k = 0; for (; __first != __last && __k < __n; ++__first, (void) ++__k) + { __output_iter[__k] = *__first; + } _Distance __sz = __k; - for (; __first != __last; ++__first, (void) ++__k) { + for (; __first != __last; ++__first, (void) ++__k) + { _Distance __r = _CUDA_VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); if (__r < __sz) + { __output_iter[__r] = *__first; + } } return __output_iter + _CUDA_VSTD::min(__n, __k); } -template -_LIBCUDACXX_INLINE_VISIBILITY -_SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output_iter, - _Distance __n, - _UniformRandomNumberGenerator& __g, - forward_iterator_tag) { +template +_LIBCUDACXX_INLINE_VISIBILITY _SampleIterator __sample( + _PopulationIterator __first, + _PopulationIterator __last, + _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator& __g, + forward_iterator_tag) +{ _Distance __unsampled_sz = _CUDA_VSTD::distance(__first, __last); - for (__n = _CUDA_VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) { - _Distance __r = - _CUDA_VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); - if (__r < __n) { + for (__n = _CUDA_VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) + { + _Distance __r = _CUDA_VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); + if (__r < __n) + { *__output_iter++ = *__first; --__n; } @@ -1068,336 +1134,360 @@ _SampleIterator __sample(_PopulationIterator __first, return __output_iter; } -template -_LIBCUDACXX_INLINE_VISIBILITY -_SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output_iter, - _Distance __n, _UniformRandomNumberGenerator& __g) { - typedef typename iterator_traits<_PopulationIterator>::iterator_category - _PopCategory; - typedef typename iterator_traits<_PopulationIterator>::difference_type - _Difference; - static_assert(__is_cpp17_forward_iterator<_PopulationIterator>::value || - __is_cpp17_random_access_iterator<_SampleIterator>::value, +template +_LIBCUDACXX_INLINE_VISIBILITY _SampleIterator __sample( + _PopulationIterator __first, + _PopulationIterator __last, + _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator& __g) +{ + typedef typename iterator_traits<_PopulationIterator>::iterator_category _PopCategory; + typedef typename iterator_traits<_PopulationIterator>::difference_type _Difference; + static_assert(__is_cpp17_forward_iterator<_PopulationIterator>::value + || __is_cpp17_random_access_iterator<_SampleIterator>::value, "SampleIterator must meet the requirements of RandomAccessIterator"); typedef typename common_type<_Distance, _Difference>::type _CommonType; _LIBCUDACXX_ASSERT(__n >= 0, "N must be a positive number."); - return _CUDA_VSTD::__sample( - __first, __last, __output_iter, _CommonType(__n), - __g, _PopCategory()); + return _CUDA_VSTD::__sample(__first, __last, __output_iter, _CommonType(__n), __g, _PopCategory()); } -#if _CCCL_STD_VER > 2014 -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_SampleIterator sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output_iter, - _Distance __n, _UniformRandomNumberGenerator&& __g) { - return _CUDA_VSTD::__sample(__first, __last, __output_iter, __n, __g); +# if _CCCL_STD_VER > 2014 +template +inline _LIBCUDACXX_INLINE_VISIBILITY _SampleIterator sample( + _PopulationIterator __first, + _PopulationIterator __last, + _SampleIterator __output_iter, + _Distance __n, + _UniformRandomNumberGenerator&& __g) +{ + return _CUDA_VSTD::__sample(__first, __last, __output_iter, __n, __g); } -#endif // _CCCL_STD_VER > 2014 +# endif // _CCCL_STD_VER > 2014 -template -_LIBCUDACXX_INLINE_VISIBILITY - void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, - _UniformRandomNumberGenerator&& __g) +template +_LIBCUDACXX_INLINE_VISIBILITY void +shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _UniformRandomNumberGenerator&& __g) { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef uniform_int_distribution _Dp; - typedef typename _Dp::param_type _Pp; - difference_type __d = __last - __first; - if (__d > 1) - { - _Dp __uid; - for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) - { - difference_type __i = __uid(__g, _Pp(0, __d)); - if (__i != difference_type(0)) - swap(*__first, *(__first + __i)); - } + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef uniform_int_distribution _Dp; + typedef typename _Dp::param_type _Pp; + difference_type __d = __last - __first; + if (__d > 1) + { + _Dp __uid; + for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) + { + difference_type __i = __uid(__g, _Pp(0, __d)); + if (__i != difference_type(0)) + { + swap(*__first, *(__first + __i)); + } } + } } // stable_partition template -_CCCL_HOST_DEVICE -_ForwardIterator -__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, - _Distance __len, _Pair __p, forward_iterator_tag __fit) +_CCCL_HOST_DEVICE _ForwardIterator __stable_partition( + _ForwardIterator __first, + _ForwardIterator __last, + _Predicate __pred, + _Distance __len, + _Pair __p, + forward_iterator_tag __fit) { - // *__first is known to be false - // __len >= 1 - if (__len == 1) - return __first; - if (__len == 2) - { - _ForwardIterator __m = __first; - if (__pred(*++__m)) - { - swap(*__first, *__m); - return __m; - } - return __first; - } - if (__len <= __p.second) - { // The buffer is big enough to use - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__p.first, __d); - // Move the falses into the temporary buffer, and the trues to the front of the line - // Update __first to always point to the end of the trues - value_type* __t = __p.first; - ::new(__t) value_type(_CUDA_VSTD::move(*__first)); - __d.__incr((value_type*)0); - ++__t; - _ForwardIterator __i = __first; - while (++__i != __last) - { - if (__pred(*__i)) - { - *__first = _CUDA_VSTD::move(*__i); - ++__first; - } - else - { - ::new(__t) value_type(_CUDA_VSTD::move(*__i)); - __d.__incr((value_type*)0); - ++__t; - } - } - // All trues now at start of range, all falses in buffer - // Move falses back into range, but don't mess up __first which points to first false - __i = __first; - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) - *__i = _CUDA_VSTD::move(*__t2); - // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer - return __first; - } - // Else not enough buffer, do in place - // __len >= 3 + // *__first is known to be false + // __len >= 1 + if (__len == 1) + { + return __first; + } + if (__len == 2) + { _ForwardIterator __m = __first; - _Distance __len2 = __len / 2; // __len2 >= 2 - _CUDA_VSTD::advance(__m, __len2); - // recurse on [__first, __m), *__first know to be false - // F????????????????? - // f m l - typedef __add_lvalue_reference_t<_Predicate> _PredRef; - _ForwardIterator __first_false = __stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit); - // TTTFFFFF?????????? - // f ff m l - // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true - _ForwardIterator __m1 = __m; - _ForwardIterator __second_false = __last; - _Distance __len_half = __len - __len2; - while (__pred(*__m1)) - { - if (++__m1 == __last) - goto __second_half_done; - --__len_half; - } - // TTTFFFFFTTTF?????? - // f ff m m1 l - __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit); + if (__pred(*++__m)) + { + swap(*__first, *__m); + return __m; + } + return __first; + } + if (__len <= __p.second) + { // The buffer is big enough to use + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr __h(__p.first, __d); + // Move the falses into the temporary buffer, and the trues to the front of the line + // Update __first to always point to the end of the trues + value_type* __t = __p.first; + ::new (__t) value_type(_CUDA_VSTD::move(*__first)); + __d.__incr((value_type*) 0); + ++__t; + _ForwardIterator __i = __first; + while (++__i != __last) + { + if (__pred(*__i)) + { + *__first = _CUDA_VSTD::move(*__i); + ++__first; + } + else + { + ::new (__t) value_type(_CUDA_VSTD::move(*__i)); + __d.__incr((value_type*) 0); + ++__t; + } + } + // All trues now at start of range, all falses in buffer + // Move falses back into range, but don't mess up __first which points to first false + __i = __first; + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) + { + *__i = _CUDA_VSTD::move(*__t2); + } + // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer + return __first; + } + // Else not enough buffer, do in place + // __len >= 3 + _ForwardIterator __m = __first; + _Distance __len2 = __len / 2; // __len2 >= 2 + _CUDA_VSTD::advance(__m, __len2); + // recurse on [__first, __m), *__first know to be false + // F????????????????? + // f m l + typedef __add_lvalue_reference_t<_Predicate> _PredRef; + _ForwardIterator __first_false = __stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit); + // TTTFFFFF?????????? + // f ff m l + // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true + _ForwardIterator __m1 = __m; + _ForwardIterator __second_false = __last; + _Distance __len_half = __len - __len2; + while (__pred(*__m1)) + { + if (++__m1 == __last) + { + goto __second_half_done; + } + --__len_half; + } + // TTTFFFFFTTTF?????? + // f ff m m1 l + __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit); __second_half_done: - // TTTFFFFFTTTTTFFFFF - // f ff m sf l - return _CUDA_VSTD::rotate(__first_false, __m, __second_false); - // TTTTTTTTFFFFFFFFFF - // | + // TTTFFFFFTTTTTFFFFF + // f ff m sf l + return _CUDA_VSTD::rotate(__first_false, __m, __second_false); + // TTTTTTTTFFFFFFFFFF + // | } template -_CCCL_HOST_DEVICE -_ForwardIterator -__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, - forward_iterator_tag) +_CCCL_HOST_DEVICE _ForwardIterator +__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag) { - const unsigned __alloc_limit = 3; // might want to make this a function of trivial assignment - // Either prove all true and return __first or point to first false - while (true) - { - if (__first == __last) - return __first; - if (!__pred(*__first)) - break; - ++__first; + const unsigned __alloc_limit = 3; // might want to make this a function of trivial assignment + // Either prove all true and return __first or point to first false + while (true) + { + if (__first == __last) + { + return __first; } - // We now have a reduced range [__first, __last) - // *__first is known to be false - typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; - typedef typename iterator_traits<_ForwardIterator>::value_type value_type; - difference_type __len = _CUDA_VSTD::distance(__first, __last); - pair __p(0, 0); - unique_ptr __h; - if (__len >= __alloc_limit) + if (!__pred(*__first)) { - __p = _CUDA_VSTD::get_temporary_buffer(__len); - __h.reset(__p.first); + break; } - return __stable_partition<__add_lvalue_reference_t<_Predicate>> - (__first, __last, __pred, __len, __p, forward_iterator_tag()); + ++__first; + } + // We now have a reduced range [__first, __last) + // *__first is known to be false + typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; + typedef typename iterator_traits<_ForwardIterator>::value_type value_type; + difference_type __len = _CUDA_VSTD::distance(__first, __last); + pair __p(0, 0); + unique_ptr __h; + if (__len >= __alloc_limit) + { + __p = _CUDA_VSTD::get_temporary_buffer(__len); + __h.reset(__p.first); + } + return __stable_partition<__add_lvalue_reference_t<_Predicate>>( + __first, __last, __pred, __len, __p, forward_iterator_tag()); } template -_CCCL_HOST_DEVICE -_BidirectionalIterator -__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, - _Distance __len, _Pair __p, bidirectional_iterator_tag __bit) +_CCCL_HOST_DEVICE _BidirectionalIterator __stable_partition( + _BidirectionalIterator __first, + _BidirectionalIterator __last, + _Predicate __pred, + _Distance __len, + _Pair __p, + bidirectional_iterator_tag __bit) { - // *__first is known to be false - // *__last is known to be true - // __len >= 2 - if (__len == 2) + // *__first is known to be false + // *__last is known to be true + // __len >= 2 + if (__len == 2) + { + swap(*__first, *__last); + return __last; + } + if (__len == 3) + { + _BidirectionalIterator __m = __first; + if (__pred(*++__m)) { - swap(*__first, *__last); - return __last; + swap(*__first, *__m); + swap(*__m, *__last); + return __last; } - if (__len == 3) + swap(*__m, *__last); + swap(*__first, *__m); + return __m; + } + if (__len <= __p.second) + { // The buffer is big enough to use + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr __h(__p.first, __d); + // Move the falses into the temporary buffer, and the trues to the front of the line + // Update __first to always point to the end of the trues + value_type* __t = __p.first; + ::new (__t) value_type(_CUDA_VSTD::move(*__first)); + __d.__incr((value_type*) 0); + ++__t; + _BidirectionalIterator __i = __first; + while (++__i != __last) { - _BidirectionalIterator __m = __first; - if (__pred(*++__m)) - { - swap(*__first, *__m); - swap(*__m, *__last); - return __last; - } - swap(*__m, *__last); - swap(*__first, *__m); - return __m; - } - if (__len <= __p.second) - { // The buffer is big enough to use - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__p.first, __d); - // Move the falses into the temporary buffer, and the trues to the front of the line - // Update __first to always point to the end of the trues - value_type* __t = __p.first; - ::new(__t) value_type(_CUDA_VSTD::move(*__first)); - __d.__incr((value_type*)0); - ++__t; - _BidirectionalIterator __i = __first; - while (++__i != __last) - { - if (__pred(*__i)) - { - *__first = _CUDA_VSTD::move(*__i); - ++__first; - } - else - { - ::new(__t) value_type(_CUDA_VSTD::move(*__i)); - __d.__incr((value_type*)0); - ++__t; - } - } - // move *__last, known to be true + if (__pred(*__i)) + { *__first = _CUDA_VSTD::move(*__i); - __i = ++__first; - // All trues now at start of range, all falses in buffer - // Move falses back into range, but don't mess up __first which points to first false - for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) - *__i = _CUDA_VSTD::move(*__t2); - // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer - return __first; - } - // Else not enough buffer, do in place - // __len >= 4 - _BidirectionalIterator __m = __first; - _Distance __len2 = __len / 2; // __len2 >= 2 - _CUDA_VSTD::advance(__m, __len2); - // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false - // F????????????????T - // f m l - _BidirectionalIterator __m1 = __m; - _BidirectionalIterator __first_false = __first; - _Distance __len_half = __len2; - while (!__pred(*--__m1)) - { - if (__m1 == __first) - goto __first_half_done; - --__len_half; - } - // F???TFFF?????????T - // f m1 m l - typedef __add_lvalue_reference_t<_Predicate> _PredRef; - __first_false = __stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit); + ++__first; + } + else + { + ::new (__t) value_type(_CUDA_VSTD::move(*__i)); + __d.__incr((value_type*) 0); + ++__t; + } + } + // move *__last, known to be true + *__first = _CUDA_VSTD::move(*__i); + __i = ++__first; + // All trues now at start of range, all falses in buffer + // Move falses back into range, but don't mess up __first which points to first false + for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i) + { + *__i = _CUDA_VSTD::move(*__t2); + } + // __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer + return __first; + } + // Else not enough buffer, do in place + // __len >= 4 + _BidirectionalIterator __m = __first; + _Distance __len2 = __len / 2; // __len2 >= 2 + _CUDA_VSTD::advance(__m, __len2); + // recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false + // F????????????????T + // f m l + _BidirectionalIterator __m1 = __m; + _BidirectionalIterator __first_false = __first; + _Distance __len_half = __len2; + while (!__pred(*--__m1)) + { + if (__m1 == __first) + { + goto __first_half_done; + } + --__len_half; + } + // F???TFFF?????????T + // f m1 m l + typedef __add_lvalue_reference_t<_Predicate> _PredRef; + __first_false = __stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit); __first_half_done: - // TTTFFFFF?????????T - // f ff m l - // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true - __m1 = __m; - _BidirectionalIterator __second_false = __last; - ++__second_false; - __len_half = __len - __len2; - while (__pred(*__m1)) - { - if (++__m1 == __last) - goto __second_half_done; - --__len_half; - } - // TTTFFFFFTTTF?????T - // f ff m m1 l - __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit); + // TTTFFFFF?????????T + // f ff m l + // recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true + __m1 = __m; + _BidirectionalIterator __second_false = __last; + ++__second_false; + __len_half = __len - __len2; + while (__pred(*__m1)) + { + if (++__m1 == __last) + { + goto __second_half_done; + } + --__len_half; + } + // TTTFFFFFTTTF?????T + // f ff m m1 l + __second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit); __second_half_done: - // TTTFFFFFTTTTTFFFFF - // f ff m sf l - return _CUDA_VSTD::rotate(__first_false, __m, __second_false); - // TTTTTTTTFFFFFFFFFF - // | + // TTTFFFFFTTTTTFFFFF + // f ff m sf l + return _CUDA_VSTD::rotate(__first_false, __m, __second_false); + // TTTTTTTTFFFFFFFFFF + // | } template -_CCCL_HOST_DEVICE -_BidirectionalIterator -__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, - bidirectional_iterator_tag) +_CCCL_HOST_DEVICE _BidirectionalIterator __stable_partition( + _BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag) { - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment - // Either prove all true and return __first or point to first false - while (true) - { - if (__first == __last) - return __first; - if (!__pred(*__first)) - break; - ++__first; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment + // Either prove all true and return __first or point to first false + while (true) + { + if (__first == __last) + { + return __first; } - // __first points to first false, everything prior to __first is already set. - // Either prove [__first, __last) is all false and return __first, or point __last to last true - do + if (!__pred(*__first)) { - if (__first == --__last) - return __first; - } while (!__pred(*__last)); - // We now have a reduced range [__first, __last] - // *__first is known to be false - // *__last is known to be true - // __len >= 2 - difference_type __len = _CUDA_VSTD::distance(__first, __last) + 1; - pair __p(0, 0); - unique_ptr __h; - if (__len >= __alloc_limit) - { - __p = _CUDA_VSTD::get_temporary_buffer(__len); - __h.reset(__p.first); - } - return __stable_partition<__add_lvalue_reference_t<_Predicate>> - (__first, __last, __pred, __len, __p, bidirectional_iterator_tag()); + break; + } + ++__first; + } + // __first points to first false, everything prior to __first is already set. + // Either prove [__first, __last) is all false and return __first, or point __last to last true + do + { + if (__first == --__last) + { + return __first; + } + } while (!__pred(*__last)); + // We now have a reduced range [__first, __last] + // *__first is known to be false + // *__last is known to be true + // __len >= 2 + difference_type __len = _CUDA_VSTD::distance(__first, __last) + 1; + pair __p(0, 0); + unique_ptr __h; + if (__len >= __alloc_limit) + { + __p = _CUDA_VSTD::get_temporary_buffer(__len); + __h.reset(__p.first); + } + return __stable_partition<__add_lvalue_reference_t<_Predicate>>( + __first, __last, __pred, __len, __p, bidirectional_iterator_tag()); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -_ForwardIterator +inline _LIBCUDACXX_INLINE_VISIBILITY _ForwardIterator stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - return __stable_partition<__add_lvalue_reference_t<_Predicate>> - (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); + return __stable_partition<__add_lvalue_reference_t<_Predicate>>( + __first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); } // sort @@ -1405,1120 +1495,1197 @@ stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate _ // stable, 2-3 compares, 0-2 swaps template -_CCCL_HOST_DEVICE -unsigned -__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) +_CCCL_HOST_DEVICE unsigned __sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) { - unsigned __r = 0; - if (!__c(*__y, *__x)) // if x <= y - { - if (!__c(*__z, *__y)) // if y <= z - return __r; // x <= y && y <= z - // x <= y && y > z - swap(*__y, *__z); // x <= z && y < z - __r = 1; - if (__c(*__y, *__x)) // if x > y - { - swap(*__x, *__y); // x < y && y <= z - __r = 2; - } - return __r; // x <= y && y < z - } - if (__c(*__z, *__y)) // x > y, if y > z + unsigned __r = 0; + if (!__c(*__y, *__x)) // if x <= y + { + if (!__c(*__z, *__y)) // if y <= z { - swap(*__x, *__z); // x < y && y < z - __r = 1; - return __r; + return __r; // x <= y && y <= z + // x <= y && y > z } - swap(*__x, *__y); // x > y && y <= z - __r = 1; // x < y && x <= z - if (__c(*__z, *__y)) // if y > z + swap(*__y, *__z); // x <= z && y < z + __r = 1; + if (__c(*__y, *__x)) // if x > y { - swap(*__y, *__z); // x <= y && y < z - __r = 2; + swap(*__x, *__y); // x < y && y <= z + __r = 2; } + return __r; // x <= y && y < z + } + if (__c(*__z, *__y)) // x > y, if y > z + { + swap(*__x, *__z); // x < y && y < z + __r = 1; return __r; -} // x <= y && y <= z + } + swap(*__x, *__y); // x > y && y <= z + __r = 1; // x < y && x <= z + if (__c(*__z, *__y)) // if y > z + { + swap(*__y, *__z); // x <= y && y < z + __r = 2; + } + return __r; +} // x <= y && y <= z // stable, 3-6 compares, 0-5 swaps template -_CCCL_HOST_DEVICE -unsigned -__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, - _ForwardIterator __x4, _Compare __c) +_CCCL_HOST_DEVICE unsigned +__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) { - unsigned __r = __sort3<_Compare>(__x1, __x2, __x3, __c); - if (__c(*__x4, *__x3)) + unsigned __r = __sort3<_Compare>(__x1, __x2, __x3, __c); + if (__c(*__x4, *__x3)) + { + swap(*__x3, *__x4); + ++__r; + if (__c(*__x3, *__x2)) { - swap(*__x3, *__x4); + swap(*__x2, *__x3); + ++__r; + if (__c(*__x2, *__x1)) + { + swap(*__x1, *__x2); ++__r; - if (__c(*__x3, *__x2)) - { - swap(*__x2, *__x3); - ++__r; - if (__c(*__x2, *__x1)) - { - swap(*__x1, *__x2); - ++__r; - } - } + } } - return __r; + } + return __r; } // stable, 4-10 compares, 0-9 swaps template -_LIBCUDACXX_HIDDEN -_CCCL_HOST_DEVICE -unsigned -__sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, - _ForwardIterator __x4, _ForwardIterator __x5, _Compare __c) +_LIBCUDACXX_HIDDEN _CCCL_HOST_DEVICE unsigned __sort5( + _ForwardIterator __x1, + _ForwardIterator __x2, + _ForwardIterator __x3, + _ForwardIterator __x4, + _ForwardIterator __x5, + _Compare __c) { - unsigned __r = __sort4<_Compare>(__x1, __x2, __x3, __x4, __c); - if (__c(*__x5, *__x4)) + unsigned __r = __sort4<_Compare>(__x1, __x2, __x3, __x4, __c); + if (__c(*__x5, *__x4)) + { + swap(*__x4, *__x5); + ++__r; + if (__c(*__x4, *__x3)) { - swap(*__x4, *__x5); + swap(*__x3, *__x4); + ++__r; + if (__c(*__x3, *__x2)) + { + swap(*__x2, *__x3); ++__r; - if (__c(*__x4, *__x3)) + if (__c(*__x2, *__x1)) { - swap(*__x3, *__x4); - ++__r; - if (__c(*__x3, *__x2)) - { - swap(*__x2, *__x3); - ++__r; - if (__c(*__x2, *__x1)) - { - swap(*__x1, *__x2); - ++__r; - } - } + swap(*__x1, *__x2); + ++__r; } + } } - return __r; + } + return __r; } // Assumes size > 0 template -_CCCL_HOST_DEVICE -void -__selection_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) +_CCCL_HOST_DEVICE void __selection_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) { - _BirdirectionalIterator __lm1 = __last; - for (--__lm1; __first != __lm1; ++__first) + _BirdirectionalIterator __lm1 = __last; + for (--__lm1; __first != __lm1; ++__first) + { + _BirdirectionalIterator __i = + _CUDA_VSTD::min_element<_BirdirectionalIterator, __add_lvalue_reference_t<_Compare>>(__first, __last, __comp); + if (__i != __first) { - _BirdirectionalIterator __i = _CUDA_VSTD::min_element<_BirdirectionalIterator, - __add_lvalue_reference_t<_Compare>> - (__first, __last, __comp); - if (__i != __first) - swap(*__first, *__i); + swap(*__first, *__i); } + } } template -_CCCL_HOST_DEVICE -void -__insertion_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) +_CCCL_HOST_DEVICE void __insertion_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp) { - typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; - if (__first != __last) + typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; + if (__first != __last) + { + _BirdirectionalIterator __i = __first; + for (++__i; __i != __last; ++__i) { - _BirdirectionalIterator __i = __first; - for (++__i; __i != __last; ++__i) - { - _BirdirectionalIterator __j = __i; - value_type __t(_CUDA_VSTD::move(*__j)); - for (_BirdirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j) - *__j = _CUDA_VSTD::move(*__k); - *__j = _CUDA_VSTD::move(__t); - } + _BirdirectionalIterator __j = __i; + value_type __t(_CUDA_VSTD::move(*__j)); + for (_BirdirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j) + { + *__j = _CUDA_VSTD::move(*__k); + } + *__j = _CUDA_VSTD::move(__t); } + } } template -_CCCL_HOST_DEVICE -void -__insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +_CCCL_HOST_DEVICE void __insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - _RandomAccessIterator __j = __first+2; - __sort3<_Compare>(__first, __first+1, __j, __comp); - for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + _RandomAccessIterator __j = __first + 2; + __sort3<_Compare>(__first, __first + 1, __j, __comp); + for (_RandomAccessIterator __i = __j + 1; __i != __last; ++__i) + { + if (__comp(*__i, *__j)) { - if (__comp(*__i, *__j)) - { - value_type __t(_CUDA_VSTD::move(*__i)); - _RandomAccessIterator __k = __j; - __j = __i; - do - { - *__j = _CUDA_VSTD::move(*__k); - __j = __k; - } while (__j != __first && __comp(__t, *--__k)); - *__j = _CUDA_VSTD::move(__t); - } - __j = __i; + value_type __t(_CUDA_VSTD::move(*__i)); + _RandomAccessIterator __k = __j; + __j = __i; + do + { + *__j = _CUDA_VSTD::move(*__k); + __j = __k; + } while (__j != __first && __comp(__t, *--__k)); + *__j = _CUDA_VSTD::move(__t); } + __j = __i; + } } template -_CCCL_HOST_DEVICE -bool +_CCCL_HOST_DEVICE bool __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - switch (__last - __first) - { + switch (__last - __first) + { case 0: case 1: - return true; + return true; case 2: - if (__comp(*--__last, *__first)) - swap(*__first, *__last); - return true; + if (__comp(*--__last, *__first)) + { + swap(*__first, *__last); + } + return true; case 3: - _CUDA_VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); - return true; + _CUDA_VSTD::__sort3<_Compare>(__first, __first + 1, --__last, __comp); + return true; case 4: - _CUDA_VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); - return true; + _CUDA_VSTD::__sort4<_Compare>(__first, __first + 1, __first + 2, --__last, __comp); + return true; case 5: - _CUDA_VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); - return true; - } - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - _RandomAccessIterator __j = __first+2; - __sort3<_Compare>(__first, __first+1, __j, __comp); - const unsigned __limit = 8; - unsigned __count = 0; - for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i) + _CUDA_VSTD::__sort5<_Compare>(__first, __first + 1, __first + 2, __first + 3, --__last, __comp); + return true; + } + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + _RandomAccessIterator __j = __first + 2; + __sort3<_Compare>(__first, __first + 1, __j, __comp); + const unsigned __limit = 8; + unsigned __count = 0; + for (_RandomAccessIterator __i = __j + 1; __i != __last; ++__i) + { + if (__comp(*__i, *__j)) { - if (__comp(*__i, *__j)) - { - value_type __t(_CUDA_VSTD::move(*__i)); - _RandomAccessIterator __k = __j; - __j = __i; - do - { - *__j = _CUDA_VSTD::move(*__k); - __j = __k; - } while (__j != __first && __comp(__t, *--__k)); - *__j = _CUDA_VSTD::move(__t); - if (++__count == __limit) - return ++__i == __last; - } - __j = __i; + value_type __t(_CUDA_VSTD::move(*__i)); + _RandomAccessIterator __k = __j; + __j = __i; + do + { + *__j = _CUDA_VSTD::move(*__k); + __j = __k; + } while (__j != __first && __comp(__t, *--__k)); + *__j = _CUDA_VSTD::move(__t); + if (++__count == __limit) + { + return ++__i == __last; + } } - return true; + __j = __i; + } + return true; } template -_CCCL_HOST_DEVICE -void -__insertion_sort_move(_BirdirectionalIterator __first1, _BirdirectionalIterator __last1, - typename iterator_traits<_BirdirectionalIterator>::value_type* __first2, _Compare __comp) +_CCCL_HOST_DEVICE void __insertion_sort_move( + _BirdirectionalIterator __first1, + _BirdirectionalIterator __last1, + typename iterator_traits<_BirdirectionalIterator>::value_type* __first2, + _Compare __comp) { - typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; - if (__first1 != __last1) - { - __destruct_n __d(0); - unique_ptr __h(__first2, __d); - value_type* __last2 = __first2; - ::new(__last2) value_type(_CUDA_VSTD::move(*__first1)); - __d.__incr((value_type*)0); - for (++__last2; ++__first1 != __last1; ++__last2) + typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type; + if (__first1 != __last1) + { + __destruct_n __d(0); + unique_ptr __h(__first2, __d); + value_type* __last2 = __first2; + ::new (__last2) value_type(_CUDA_VSTD::move(*__first1)); + __d.__incr((value_type*) 0); + for (++__last2; ++__first1 != __last1; ++__last2) + { + value_type* __j2 = __last2; + value_type* __i2 = __j2; + if (__comp(*__first1, *--__i2)) + { + ::new (__j2) value_type(_CUDA_VSTD::move(*__i2)); + __d.__incr((value_type*) 0); + for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) { - value_type* __j2 = __last2; - value_type* __i2 = __j2; - if (__comp(*__first1, *--__i2)) - { - ::new(__j2) value_type(_CUDA_VSTD::move(*__i2)); - __d.__incr((value_type*)0); - for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) - *__j2 = _CUDA_VSTD::move(*__i2); - *__j2 = _CUDA_VSTD::move(*__first1); - } - else - { - ::new(__j2) value_type(_CUDA_VSTD::move(*__first1)); - __d.__incr((value_type*)0); - } + *__j2 = _CUDA_VSTD::move(*__i2); } - __h.release(); + *__j2 = _CUDA_VSTD::move(*__first1); + } + else + { + ::new (__j2) value_type(_CUDA_VSTD::move(*__first1)); + __d.__incr((value_type*) 0); + } } + __h.release(); + } } template -_CCCL_HOST_DEVICE -void -__sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +_CCCL_HOST_DEVICE void __sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - // _Compare is known to be a reference type - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - const difference_type __limit = is_trivially_copy_constructible::value && - is_trivially_copy_assignable::value ? 30 : 6; - while (true) - { - __restart: - difference_type __len = __last - __first; - switch (__len) - { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - swap(*__first, *__last); - return; - case 3: - _CUDA_VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp); - return; - case 4: - _CUDA_VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp); - return; - case 5: - _CUDA_VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp); - return; - } - if (__len <= __limit) - { - _CUDA_VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp); - return; - } - // __len > 5 - _RandomAccessIterator __m = __first; - _RandomAccessIterator __lm1 = __last; - --__lm1; - unsigned __n_swaps; - { - difference_type __delta; - if (__len >= 1000) - { - __delta = __len/2; - __m += __delta; - __delta /= 2; - __n_swaps = _CUDA_VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp); - } - else - { - __delta = __len/2; - __m += __delta; - __n_swaps = _CUDA_VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp); - } - } - // *__m is median - // partition [__first, __m) < *__m and *__m <= [__m, __last) - // (this inhibits tossing elements equivalent to __m around unnecessarily) - _RandomAccessIterator __i = __first; - _RandomAccessIterator __j = __lm1; - // j points beyond range to be tested, *__m is known to be <= *__lm1 - // The search going up is known to be guarded but the search coming down isn't. - // Prime the downward search with a guard. - if (!__comp(*__i, *__m)) // if *__first == *__m + // _Compare is known to be a reference type + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + const difference_type __limit = + is_trivially_copy_constructible::value && is_trivially_copy_assignable::value ? 30 : 6; + while (true) + { + __restart: + difference_type __len = __last - __first; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) { - // *__first == *__m, *__first doesn't go in first part - // manually guard downward moving __j against __i - while (true) - { - if (__i == --__j) - { - // *__first == *__m, *__m <= all other elements - // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) - ++__i; // __first + 1 - __j = __last; - if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) - { - while (true) - { - if (__i == __j) - return; // [__first, __last) all equivalent elements - if (__comp(*__first, *__i)) - { - swap(*__i, *__j); - ++__n_swaps; - ++__i; - break; - } - ++__i; - } - } - // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 - if (__i == __j) - return; - while (true) - { - while (!__comp(*__first, *__i)) - ++__i; - while (__comp(*__first, *--__j)) - ; - if (__i >= __j) - break; - swap(*__i, *__j); - ++__n_swaps; - ++__i; - } - // [__first, __i) == *__first and *__first < [__i, __last) - // The first part is sorted, sort the secod part - // _CUDA_VSTD::__sort<_Compare>(__i, __last, __comp); - __first = __i; - goto __restart; - } - if (__comp(*__j, *__m)) - { - swap(*__i, *__j); - ++__n_swaps; - break; // found guard for downward moving __j, now use unguarded partition - } - } + swap(*__first, *__last); } - // It is known that *__i < *__m - ++__i; - // j points beyond range to be tested, *__m is known to be <= *__lm1 - // if not yet partitioned... - if (__i < __j) + return; + case 3: + _CUDA_VSTD::__sort3<_Compare>(__first, __first + 1, --__last, __comp); + return; + case 4: + _CUDA_VSTD::__sort4<_Compare>(__first, __first + 1, __first + 2, --__last, __comp); + return; + case 5: + _CUDA_VSTD::__sort5<_Compare>(__first, __first + 1, __first + 2, __first + 3, --__last, __comp); + return; + } + if (__len <= __limit) + { + _CUDA_VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp); + return; + } + // __len > 5 + _RandomAccessIterator __m = __first; + _RandomAccessIterator __lm1 = __last; + --__lm1; + unsigned __n_swaps; + { + difference_type __delta; + if (__len >= 1000) + { + __delta = __len / 2; + __m += __delta; + __delta /= 2; + __n_swaps = _CUDA_VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m + __delta, __lm1, __comp); + } + else + { + __delta = __len / 2; + __m += __delta; + __n_swaps = _CUDA_VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp); + } + } + // *__m is median + // partition [__first, __m) < *__m and *__m <= [__m, __last) + // (this inhibits tossing elements equivalent to __m around unnecessarily) + _RandomAccessIterator __i = __first; + _RandomAccessIterator __j = __lm1; + // j points beyond range to be tested, *__m is known to be <= *__lm1 + // The search going up is known to be guarded but the search coming down isn't. + // Prime the downward search with a guard. + if (!__comp(*__i, *__m)) // if *__first == *__m + { + // *__first == *__m, *__first doesn't go in first part + // manually guard downward moving __j against __i + while (true) + { + if (__i == --__j) { - // known that *(__i - 1) < *__m - // known that __i <= __m + // *__first == *__m, *__m <= all other elements + // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) + ++__i; // __first + 1 + __j = __last; + if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) + { while (true) { - // __m still guards upward moving __i - while (__comp(*__i, *__m)) - ++__i; - // It is now known that a guard exists for downward moving __j - while (!__comp(*--__j, *__m)) - ; - if (__i > __j) - break; + if (__i == __j) + { + return; // [__first, __last) all equivalent elements + } + if (__comp(*__first, *__i)) + { swap(*__i, *__j); ++__n_swaps; - // It is known that __m != __j - // If __m just moved, follow it - if (__m == __i) - __m = __j; ++__i; + break; + } + ++__i; } - } - // [__first, __i) < *__m and *__m <= [__i, __last) - if (__i != __m && __comp(*__m, *__i)) - { - swap(*__i, *__m); - ++__n_swaps; - } - // [__first, __i) < *__i and *__i <= [__i+1, __last) - // If we were given a perfect partition, see if insertion sort is quick... - if (__n_swaps == 0) - { - bool __fs = _CUDA_VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp); - if (_CUDA_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp)) + } + // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 + if (__i == __j) + { + return; + } + while (true) + { + while (!__comp(*__first, *__i)) { - if (__fs) - return; - __last = __i; - continue; + ++__i; } - else + while (__comp(*__first, *--__j)) + ; + if (__i >= __j) { - if (__fs) - { - __first = ++__i; - continue; - } + break; } + swap(*__i, *__j); + ++__n_swaps; + ++__i; + } + // [__first, __i) == *__first and *__first < [__i, __last) + // The first part is sorted, sort the secod part + // _CUDA_VSTD::__sort<_Compare>(__i, __last, __comp); + __first = __i; + goto __restart; + } + if (__comp(*__j, *__m)) + { + swap(*__i, *__j); + ++__n_swaps; + break; // found guard for downward moving __j, now use unguarded partition + } + } + } + // It is known that *__i < *__m + ++__i; + // j points beyond range to be tested, *__m is known to be <= *__lm1 + // if not yet partitioned... + if (__i < __j) + { + // known that *(__i - 1) < *__m + // known that __i <= __m + while (true) + { + // __m still guards upward moving __i + while (__comp(*__i, *__m)) + { + ++__i; + } + // It is now known that a guard exists for downward moving __j + while (!__comp(*--__j, *__m)) + ; + if (__i > __j) + { + break; } - // sort smaller range with recursive call and larger with tail recursion elimination - if (__i - __first < __last - __i) + swap(*__i, *__j); + ++__n_swaps; + // It is known that __m != __j + // If __m just moved, follow it + if (__m == __i) { - _CUDA_VSTD::__sort<_Compare>(__first, __i, __comp); - // _CUDA_VSTD::__sort<_Compare>(__i+1, __last, __comp); - __first = ++__i; + __m = __j; } - else + ++__i; + } + } + // [__first, __i) < *__m and *__m <= [__i, __last) + if (__i != __m && __comp(*__m, *__i)) + { + swap(*__i, *__m); + ++__n_swaps; + } + // [__first, __i) < *__i and *__i <= [__i+1, __last) + // If we were given a perfect partition, see if insertion sort is quick... + if (__n_swaps == 0) + { + bool __fs = _CUDA_VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp); + if (_CUDA_VSTD::__insertion_sort_incomplete<_Compare>(__i + 1, __last, __comp)) + { + if (__fs) { - _CUDA_VSTD::__sort<_Compare>(__i+1, __last, __comp); - // _CUDA_VSTD::__sort<_Compare>(__first, __i, __comp); - __last = __i; + return; } + __last = __i; + continue; + } + else + { + if (__fs) + { + __first = ++__i; + continue; + } + } + } + // sort smaller range with recursive call and larger with tail recursion elimination + if (__i - __first < __last - __i) + { + _CUDA_VSTD::__sort<_Compare>(__first, __i, __comp); + // _CUDA_VSTD::__sort<_Compare>(__i+1, __last, __comp); + __first = ++__i; + } + else + { + _CUDA_VSTD::__sort<_Compare>(__i + 1, __last, __comp); + // _CUDA_VSTD::__sort<_Compare>(__first, __i, __comp); + __last = __i; } + } } // This forwarder keeps the top call and the recursive calls using the same instantiation, forcing a reference _Compare template -inline _LIBCUDACXX_INLINE_VISIBILITY -void +inline _LIBCUDACXX_INLINE_VISIBILITY void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - using _Comp_ref = __comp_ref_type<_Compare>; - _CUDA_VSTD::__sort<_Comp_ref>(__first, __last, _Comp_ref(__comp)); + using _Comp_ref = __comp_ref_type<_Compare>; + _CUDA_VSTD::__sort<_Comp_ref>(__first, __last, _Comp_ref(__comp)); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +inline _LIBCUDACXX_INLINE_VISIBILITY void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { - _CUDA_VSTD::sort(__first, __last, __less{}); + _CUDA_VSTD::sort(__first, __last, __less{}); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -sort(_Tp** __first, _Tp** __last) +inline _LIBCUDACXX_INLINE_VISIBILITY void sort(_Tp** __first, _Tp** __last) { - _CUDA_VSTD::sort((size_t*)__first, (size_t*)__last, __less{}); + _CUDA_VSTD::sort((size_t*) __first, (size_t*) __last, __less{}); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last) +inline _LIBCUDACXX_INLINE_VISIBILITY void sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last) { - _CUDA_VSTD::sort(__first.base(), __last.base()); + _CUDA_VSTD::sort(__first.base(), __last.base()); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp) +inline _LIBCUDACXX_INLINE_VISIBILITY void sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp) { - typedef __add_lvalue_reference_t<_Compare> _Comp_ref; - _CUDA_VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp); + typedef __add_lvalue_reference_t<_Compare> _Comp_ref; + _CUDA_VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp); } _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, char*>(char*, char*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, signed*>(signed*, signed*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, short*>(short*, short*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, int*>(int*, int*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned*>(unsigned*, unsigned*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, long*>(long*, long*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, long long*>(long long*, long long*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS void __sort<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, float*>(float*, float*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, double*>(double*, double*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS void __sort<__less&, long double*>(long double*, long double*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, char*>(char*, char*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, signed char*>(signed char*, signed char*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, short*>(short*, short*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, signed char*>(signed char*, signed char*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned char*>( + unsigned char*, unsigned char*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, short*>(short*, short*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned short*>( + unsigned short*, unsigned short*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, int*>(int*, int*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned*>(unsigned*, unsigned*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned*>(unsigned*, unsigned*, __less&)) _LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, long*>(long*, long*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, long long*>(long long*, long long*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, float*>(float*, float*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, double*>(double*, double*, __less&)) -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, long double*>(long double*, long double*, __less&)) - -_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS unsigned __sort5<__less&, long double*>(long double*, long double*, long double*, long double*, long double*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned long*>( + unsigned long*, unsigned long*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, long long*>(long long*, long long*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, unsigned long long*>( + unsigned long long*, unsigned long long*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, float*>(float*, float*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, double*>(double*, double*, __less&)) +_LIBCUDACXX_EXTERN_TEMPLATE( + _LIBCUDACXX_FUNC_VIS bool __insertion_sort_incomplete<__less&, long double*>(long double*, long double*, __less&)) + +_LIBCUDACXX_EXTERN_TEMPLATE(_LIBCUDACXX_FUNC_VIS unsigned __sort5<__less&, long double*>( + long double*, long double*, long double*, long double*, long double*, __less&)) // inplace_merge -template -_CCCL_HOST_DEVICE -void __half_inplace_merge(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) +template +_CCCL_HOST_DEVICE void __half_inplace_merge( + _InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _InputIterator2 __last2, + _OutputIterator __result, + _Compare __comp) { - for (; __first1 != __last1; ++__result) + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) { - if (__first2 == __last2) - { - _CUDA_VSTD::move(__first1, __last1, __result); - return; - } + _CUDA_VSTD::move(__first1, __last1, __result); + return; + } - if (__comp(*__first2, *__first1)) - { - *__result = _CUDA_VSTD::move(*__first2); - ++__first2; - } - else - { - *__result = _CUDA_VSTD::move(*__first1); - ++__first1; - } + if (__comp(*__first2, *__first1)) + { + *__result = _CUDA_VSTD::move(*__first2); + ++__first2; + } + else + { + *__result = _CUDA_VSTD::move(*__first1); + ++__first1; } - // __first2 through __last2 are already in the right spot. + } + // __first2 through __last2 are already in the right spot. } template -_CCCL_HOST_DEVICE -void -__buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, - _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, - typename iterator_traits<_BidirectionalIterator>::difference_type __len2, - typename iterator_traits<_BidirectionalIterator>::value_type* __buff) +_CCCL_HOST_DEVICE void __buffered_inplace_merge( + _BidirectionalIterator __first, + _BidirectionalIterator __middle, + _BidirectionalIterator __last, + _Compare __comp, + typename iterator_traits<_BidirectionalIterator>::difference_type __len1, + typename iterator_traits<_BidirectionalIterator>::difference_type __len2, + typename iterator_traits<_BidirectionalIterator>::value_type* __buff) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h2(__buff, __d); - if (__len1 <= __len2) + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + __destruct_n __d(0); + unique_ptr __h2(__buff, __d); + if (__len1 <= __len2) + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*) 0), (void) ++__i, (void) ++__p) { - value_type* __p = __buff; - for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p) - ::new(__p) value_type(_CUDA_VSTD::move(*__i)); - __half_inplace_merge(__buff, __p, __middle, __last, __first, __comp); + ::new (__p) value_type(_CUDA_VSTD::move(*__i)); } - else + __half_inplace_merge(__buff, __p, __middle, __last, __first, __comp); + } + else + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*) 0), (void) ++__i, (void) ++__p) { - value_type* __p = __buff; - for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p) - ::new(__p) value_type(_CUDA_VSTD::move(*__i)); - typedef reverse_iterator<_BidirectionalIterator> _RBi; - typedef reverse_iterator _Rv; - __half_inplace_merge(_Rv(__p), _Rv(__buff), - _RBi(__middle), _RBi(__first), - _RBi(__last), __invert<_Compare>(__comp)); + ::new (__p) value_type(_CUDA_VSTD::move(*__i)); } + typedef reverse_iterator<_BidirectionalIterator> _RBi; + typedef reverse_iterator _Rv; + __half_inplace_merge(_Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), __invert<_Compare>(__comp)); + } } template -_CCCL_HOST_DEVICE -void -__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, - _Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1, - typename iterator_traits<_BidirectionalIterator>::difference_type __len2, - typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size) +_CCCL_HOST_DEVICE void __inplace_merge( + _BidirectionalIterator __first, + _BidirectionalIterator __middle, + _BidirectionalIterator __last, + _Compare __comp, + typename iterator_traits<_BidirectionalIterator>::difference_type __len1, + typename iterator_traits<_BidirectionalIterator>::difference_type __len2, + typename iterator_traits<_BidirectionalIterator>::value_type* __buff, + ptrdiff_t __buff_size) { - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - while (true) + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + while (true) + { + // if __middle == __last, we're done + if (__len2 == 0) { - // if __middle == __last, we're done - if (__len2 == 0) - return; - if (__len1 <= __buff_size || __len2 <= __buff_size) - return __buffered_inplace_merge<_Compare> - (__first, __middle, __last, __comp, __len1, __len2, __buff); - // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 - for (; true; ++__first, (void) --__len1) - { - if (__len1 == 0) - return; - if (__comp(*__middle, *__first)) - break; - } - // __first < __middle < __last - // *__first > *__middle - // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that - // all elements in: - // [__first, __m1) <= [__middle, __m2) - // [__middle, __m2) < [__m1, __middle) - // [__m1, __middle) <= [__m2, __last) - // and __m1 or __m2 is in the middle of its range - _BidirectionalIterator __m1; // "median" of [__first, __middle) - _BidirectionalIterator __m2; // "median" of [__middle, __last) - difference_type __len11; // distance(__first, __m1) - difference_type __len21; // distance(__middle, __m2) - // binary search smaller range - if (__len1 < __len2) - { // __len >= 1, __len2 >= 2 - __len21 = __len2 / 2; - __m2 = __middle; - _CUDA_VSTD::advance(__m2, __len21); - __m1 = __upper_bound<_Compare>(__first, __middle, *__m2, __comp); - __len11 = _CUDA_VSTD::distance(__first, __m1); - } - else - { - if (__len1 == 1) - { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1 - // It is known *__first > *__middle - swap(*__first, *__middle); - return; - } - // __len1 >= 2, __len2 >= 1 - __len11 = __len1 / 2; - __m1 = __first; - _CUDA_VSTD::advance(__m1, __len11); - __m2 = __lower_bound<_Compare>(__middle, __last, *__m1, __comp); - __len21 = _CUDA_VSTD::distance(__middle, __m2); - } - difference_type __len12 = __len1 - __len11; // distance(__m1, __middle) - difference_type __len22 = __len2 - __len21; // distance(__m2, __last) - // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) - // swap middle two partitions - __middle = _CUDA_VSTD::rotate(__m1, __middle, __m2); - // __len12 and __len21 now have swapped meanings - // merge smaller range with recurisve call and larger with tail recursion elimination - if (__len11 + __len21 < __len12 + __len22) - { - __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); -// __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); - __first = __middle; - __middle = __m2; - __len1 = __len12; - __len2 = __len22; - } - else - { - __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); -// __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); - __last = __middle; - __middle = __m1; - __len1 = __len11; - __len2 = __len21; - } + return; + } + if (__len1 <= __buff_size || __len2 <= __buff_size) + { + return __buffered_inplace_merge<_Compare>(__first, __middle, __last, __comp, __len1, __len2, __buff); + } + // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 + for (; true; ++__first, (void) --__len1) + { + if (__len1 == 0) + { + return; + } + if (__comp(*__middle, *__first)) + { + break; + } + } + // __first < __middle < __last + // *__first > *__middle + // partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that + // all elements in: + // [__first, __m1) <= [__middle, __m2) + // [__middle, __m2) < [__m1, __middle) + // [__m1, __middle) <= [__m2, __last) + // and __m1 or __m2 is in the middle of its range + _BidirectionalIterator __m1; // "median" of [__first, __middle) + _BidirectionalIterator __m2; // "median" of [__middle, __last) + difference_type __len11; // distance(__first, __m1) + difference_type __len21; // distance(__middle, __m2) + // binary search smaller range + if (__len1 < __len2) + { // __len >= 1, __len2 >= 2 + __len21 = __len2 / 2; + __m2 = __middle; + _CUDA_VSTD::advance(__m2, __len21); + __m1 = __upper_bound<_Compare>(__first, __middle, *__m2, __comp); + __len11 = _CUDA_VSTD::distance(__first, __m1); + } + else + { + if (__len1 == 1) + { // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1 + // It is known *__first > *__middle + swap(*__first, *__middle); + return; + } + // __len1 >= 2, __len2 >= 1 + __len11 = __len1 / 2; + __m1 = __first; + _CUDA_VSTD::advance(__m1, __len11); + __m2 = __lower_bound<_Compare>(__middle, __last, *__m1, __comp); + __len21 = _CUDA_VSTD::distance(__middle, __m2); + } + difference_type __len12 = __len1 - __len11; // distance(__m1, __middle) + difference_type __len22 = __len2 - __len21; // distance(__m2, __last) + // [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) + // swap middle two partitions + __middle = _CUDA_VSTD::rotate(__m1, __middle, __m2); + // __len12 and __len21 now have swapped meanings + // merge smaller range with recurisve call and larger with tail recursion elimination + if (__len11 + __len21 < __len12 + __len22) + { + __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); + // __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); + __first = __middle; + __middle = __m2; + __len1 = __len12; + __len2 = __len22; + } + else + { + __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size); + // __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size); + __last = __middle; + __middle = __m1; + __len1 = __len11; + __len2 = __len21; } + } } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, - _Compare __comp) +inline _LIBCUDACXX_INLINE_VISIBILITY void inplace_merge( + _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp) { - typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; - typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - difference_type __len1 = _CUDA_VSTD::distance(__first, __middle); - difference_type __len2 = _CUDA_VSTD::distance(__middle, __last); - difference_type __buf_size = _CUDA_VSTD::min(__len1, __len2); - pair __buf = _CUDA_VSTD::get_temporary_buffer(__buf_size); - unique_ptr __h(__buf.first); - using _Comp_ref = __comp_ref_type<_Compare>; - return _CUDA_VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2, - __buf.first, __buf.second); + typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + difference_type __len1 = _CUDA_VSTD::distance(__first, __middle); + difference_type __len2 = _CUDA_VSTD::distance(__middle, __last); + difference_type __buf_size = _CUDA_VSTD::min(__len1, __len2); + pair __buf = _CUDA_VSTD::get_temporary_buffer(__buf_size); + unique_ptr __h(__buf.first); + using _Comp_ref = __comp_ref_type<_Compare>; + return _CUDA_VSTD::__inplace_merge<_Comp_ref>( + __first, __middle, __last, __comp, __len1, __len2, __buf.first, __buf.second); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void +inline _LIBCUDACXX_INLINE_VISIBILITY void inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) { - _CUDA_VSTD::inplace_merge(__first, __middle, __last, - __less{}); + _CUDA_VSTD::inplace_merge(__first, __middle, __last, __less{}); } // stable_sort template -_CCCL_HOST_DEVICE -void -__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp) +_CCCL_HOST_DEVICE void __merge_move_construct( + _InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _InputIterator2 __last2, + typename iterator_traits<_InputIterator1>::value_type* __result, + _Compare __comp) { - typedef typename iterator_traits<_InputIterator1>::value_type value_type; - __destruct_n __d(0); - unique_ptr __h(__result, __d); - for (; true; ++__result) + typedef typename iterator_traits<_InputIterator1>::value_type value_type; + __destruct_n __d(0); + unique_ptr __h(__result, __d); + for (; true; ++__result) + { + if (__first1 == __last1) { - if (__first1 == __last1) - { - for (; __first2 != __last2; ++__first2, ++__result, (void) __d.__incr((value_type*)0)) - ::new (__result) value_type(_CUDA_VSTD::move(*__first2)); - __h.release(); - return; - } - if (__first2 == __last2) - { - for (; __first1 != __last1; ++__first1, ++__result, (void) __d.__incr((value_type*)0)) - ::new (__result) value_type(_CUDA_VSTD::move(*__first1)); - __h.release(); - return; - } - if (__comp(*__first2, *__first1)) - { - ::new (__result) value_type(_CUDA_VSTD::move(*__first2)); - __d.__incr((value_type*)0); - ++__first2; - } - else - { - ::new (__result) value_type(_CUDA_VSTD::move(*__first1)); - __d.__incr((value_type*)0); - ++__first1; - } + for (; __first2 != __last2; ++__first2, ++__result, (void) __d.__incr((value_type*) 0)) + { + ::new (__result) value_type(_CUDA_VSTD::move(*__first2)); + } + __h.release(); + return; + } + if (__first2 == __last2) + { + for (; __first1 != __last1; ++__first1, ++__result, (void) __d.__incr((value_type*) 0)) + { + ::new (__result) value_type(_CUDA_VSTD::move(*__first1)); + } + __h.release(); + return; + } + if (__comp(*__first2, *__first1)) + { + ::new (__result) value_type(_CUDA_VSTD::move(*__first2)); + __d.__incr((value_type*) 0); + ++__first2; + } + else + { + ::new (__result) value_type(_CUDA_VSTD::move(*__first1)); + __d.__incr((value_type*) 0); + ++__first1; } + } } template -_CCCL_HOST_DEVICE -void -__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) +_CCCL_HOST_DEVICE void __merge_move_assign( + _InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _InputIterator2 __last2, + _OutputIterator __result, + _Compare __comp) { - for (; __first1 != __last1; ++__result) + for (; __first1 != __last1; ++__result) + { + if (__first2 == __last2) { - if (__first2 == __last2) - { - for (; __first1 != __last1; ++__first1, (void) ++__result) - *__result = _CUDA_VSTD::move(*__first1); - return; - } - if (__comp(*__first2, *__first1)) - { - *__result = _CUDA_VSTD::move(*__first2); - ++__first2; - } - else - { - *__result = _CUDA_VSTD::move(*__first1); - ++__first1; - } + for (; __first1 != __last1; ++__first1, (void) ++__result) + { + *__result = _CUDA_VSTD::move(*__first1); + } + return; + } + if (__comp(*__first2, *__first1)) + { + *__result = _CUDA_VSTD::move(*__first2); + ++__first2; + } + else + { + *__result = _CUDA_VSTD::move(*__first1); + ++__first1; } - for (; __first2 != __last2; ++__first2, (void) ++__result) - *__result = _CUDA_VSTD::move(*__first2); + } + for (; __first2 != __last2; ++__first2, (void) ++__result) + { + *__result = _CUDA_VSTD::move(*__first2); + } } template -_CCCL_HOST_DEVICE -void -__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size); +_CCCL_HOST_DEVICE void __stable_sort( + _RandomAccessIterator __first, + _RandomAccessIterator __last, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, + ptrdiff_t __buff_size); template -_CCCL_HOST_DEVICE -void -__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __first2) +_CCCL_HOST_DEVICE void __stable_sort_move( + _RandomAccessIterator __first1, + _RandomAccessIterator __last1, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __first2) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - switch (__len) - { + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + switch (__len) + { case 0: - return; + return; case 1: - ::new(__first2) value_type(_CUDA_VSTD::move(*__first1)); - return; + ::new (__first2) value_type(_CUDA_VSTD::move(*__first1)); + return; case 2: - __destruct_n __d(0); - unique_ptr __h2(__first2, __d); - if (__comp(*--__last1, *__first1)) - { - ::new(__first2) value_type(_CUDA_VSTD::move(*__last1)); - __d.__incr((value_type*)0); - ++__first2; - ::new(__first2) value_type(_CUDA_VSTD::move(*__first1)); - } - else - { - ::new(__first2) value_type(_CUDA_VSTD::move(*__first1)); - __d.__incr((value_type*)0); - ++__first2; - ::new(__first2) value_type(_CUDA_VSTD::move(*__last1)); - } - __h2.release(); - return; - } - if (__len <= 8) - { - __insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp); - return; - } - typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; - _RandomAccessIterator __m = __first1 + __l2; - __stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2); - __stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2); - __merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp); + __destruct_n __d(0); + unique_ptr __h2(__first2, __d); + if (__comp(*--__last1, *__first1)) + { + ::new (__first2) value_type(_CUDA_VSTD::move(*__last1)); + __d.__incr((value_type*) 0); + ++__first2; + ::new (__first2) value_type(_CUDA_VSTD::move(*__first1)); + } + else + { + ::new (__first2) value_type(_CUDA_VSTD::move(*__first1)); + __d.__incr((value_type*) 0); + ++__first2; + ::new (__first2) value_type(_CUDA_VSTD::move(*__last1)); + } + __h2.release(); + return; + } + if (__len <= 8) + { + __insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp); + return; + } + typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; + _RandomAccessIterator __m = __first1 + __l2; + __stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2); + __stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2); + __merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp); } template struct __stable_sort_switch { - static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value; + static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value; }; template -_CCCL_HOST_DEVICE -void -__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size) +_CCCL_HOST_DEVICE void __stable_sort( + _RandomAccessIterator __first, + _RandomAccessIterator __last, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, + ptrdiff_t __buff_size) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - switch (__len) - { + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + switch (__len) + { case 0: case 1: - return; + return; case 2: - if (__comp(*--__last, *__first)) - swap(*__first, *__last); - return; - } - if (__len <= static_cast(__stable_sort_switch::value)) - { - __insertion_sort<_Compare>(__first, __last, __comp); - return; - } - typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; - _RandomAccessIterator __m = __first + __l2; - if (__len <= __buff_size) - { - __destruct_n __d(0); - unique_ptr __h2(__buff, __d); - __stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff); - __d.__set(__l2, (value_type*)0); - __stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2); - __d.__set(__len, (value_type*)0); - __merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); -// __merge<_Compare>(move_iterator(__buff), -// move_iterator(__buff + __l2), -// move_iterator<_RandomAccessIterator>(__buff + __l2), -// move_iterator<_RandomAccessIterator>(__buff + __len), -// __first, __comp); - return; - } - __stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size); - __stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size); - __inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size); + if (__comp(*--__last, *__first)) + { + swap(*__first, *__last); + } + return; + } + if (__len <= static_cast(__stable_sort_switch::value)) + { + __insertion_sort<_Compare>(__first, __last, __comp); + return; + } + typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; + _RandomAccessIterator __m = __first + __l2; + if (__len <= __buff_size) + { + __destruct_n __d(0); + unique_ptr __h2(__buff, __d); + __stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff); + __d.__set(__l2, (value_type*) 0); + __stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2); + __d.__set(__len, (value_type*) 0); + __merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp); + // __merge<_Compare>(move_iterator(__buff), + // move_iterator(__buff + __l2), + // move_iterator<_RandomAccessIterator>(__buff + __l2), + // move_iterator<_RandomAccessIterator>(__buff + __len), + // __first, __comp); + return; + } + __stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size); + __stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size); + __inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void +inline _LIBCUDACXX_INLINE_VISIBILITY void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - difference_type __len = __last - __first; - pair __buf(0, 0); - unique_ptr __h; - if (__len > static_cast(__stable_sort_switch::value)) - { - __buf = _CUDA_VSTD::get_temporary_buffer(__len); - __h.reset(__buf.first); - } - using _Comp_ref = __comp_ref_type<_Compare>; - __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + difference_type __len = __last - __first; + pair __buf(0, 0); + unique_ptr __h; + if (__len > static_cast(__stable_sort_switch::value)) + { + __buf = _CUDA_VSTD::get_temporary_buffer(__len); + __h.reset(__buf.first); + } + using _Comp_ref = __comp_ref_type<_Compare>; + __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +inline _LIBCUDACXX_INLINE_VISIBILITY void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { - _CUDA_VSTD::stable_sort(__first, __last, __less{}); + _CUDA_VSTD::stable_sort(__first, __last, __less{}); } // nth_element template -_CCCL_HOST_DEVICE -void +_CCCL_HOST_DEVICE void __nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { - // _Compare is known to be a reference type - typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; - const difference_type __limit = 7; - while (true) + // _Compare is known to be a reference type + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + const difference_type __limit = 7; + while (true) + { + __restart: + if (__nth == __last) { - __restart: - if (__nth == __last) - return; - difference_type __len = __last - __first; - switch (__len) - { - case 0: - case 1: - return; - case 2: - if (__comp(*--__last, *__first)) - swap(*__first, *__last); - return; - case 3: - { - _RandomAccessIterator __m = __first; - _CUDA_VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp); - return; - } - } - if (__len <= __limit) - { - __selection_sort<_Compare>(__first, __last, __comp); - return; - } - // __len > __limit >= 3 - _RandomAccessIterator __m = __first + __len/2; - _RandomAccessIterator __lm1 = __last; - unsigned __n_swaps = _CUDA_VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp); - // *__m is median - // partition [__first, __m) < *__m and *__m <= [__m, __last) - // (this inhibits tossing elements equivalent to __m around unnecessarily) - _RandomAccessIterator __i = __first; - _RandomAccessIterator __j = __lm1; - // j points beyond range to be tested, *__lm1 is known to be <= *__m - // The search going up is known to be guarded but the search coming down isn't. - // Prime the downward search with a guard. - if (!__comp(*__i, *__m)) // if *__first == *__m + return; + } + difference_type __len = __last - __first; + switch (__len) + { + case 0: + case 1: + return; + case 2: + if (__comp(*--__last, *__first)) { - // *__first == *__m, *__first doesn't go in first part - // manually guard downward moving __j against __i - while (true) - { - if (__i == --__j) - { - // *__first == *__m, *__m <= all other elements - // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) - ++__i; // __first + 1 - __j = __last; - if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) - { - while (true) - { - if (__i == __j) - return; // [__first, __last) all equivalent elements - if (__comp(*__first, *__i)) - { - swap(*__i, *__j); - ++__n_swaps; - ++__i; - break; - } - ++__i; - } - } - // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 - if (__i == __j) - return; - while (true) - { - while (!__comp(*__first, *__i)) - ++__i; - while (__comp(*__first, *--__j)) - ; - if (__i >= __j) - break; - swap(*__i, *__j); - ++__n_swaps; - ++__i; - } - // [__first, __i) == *__first and *__first < [__i, __last) - // The first part is sorted, - if (__nth < __i) - return; - // __nth_element the secod part - // __nth_element<_Compare>(__i, __nth, __last, __comp); - __first = __i; - goto __restart; - } - if (__comp(*__j, *__m)) - { - swap(*__i, *__j); - ++__n_swaps; - break; // found guard for downward moving __j, now use unguarded partition - } - } + swap(*__first, *__last); } - ++__i; - // j points beyond range to be tested, *__lm1 is known to be <= *__m - // if not yet partitioned... - if (__i < __j) + return; + case 3: { + _RandomAccessIterator __m = __first; + _CUDA_VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp); + return; + } + } + if (__len <= __limit) + { + __selection_sort<_Compare>(__first, __last, __comp); + return; + } + // __len > __limit >= 3 + _RandomAccessIterator __m = __first + __len / 2; + _RandomAccessIterator __lm1 = __last; + unsigned __n_swaps = _CUDA_VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp); + // *__m is median + // partition [__first, __m) < *__m and *__m <= [__m, __last) + // (this inhibits tossing elements equivalent to __m around unnecessarily) + _RandomAccessIterator __i = __first; + _RandomAccessIterator __j = __lm1; + // j points beyond range to be tested, *__lm1 is known to be <= *__m + // The search going up is known to be guarded but the search coming down isn't. + // Prime the downward search with a guard. + if (!__comp(*__i, *__m)) // if *__first == *__m + { + // *__first == *__m, *__first doesn't go in first part + // manually guard downward moving __j against __i + while (true) + { + if (__i == --__j) { - // known that *(__i - 1) < *__m + // *__first == *__m, *__m <= all other elements + // Parition instead into [__first, __i) == *__first and *__first < [__i, __last) + ++__i; // __first + 1 + __j = __last; + if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1) + { while (true) { - // __m still guards upward moving __i - while (__comp(*__i, *__m)) - ++__i; - // It is now known that a guard exists for downward moving __j - while (!__comp(*--__j, *__m)) - ; - if (__i >= __j) - break; + if (__i == __j) + { + return; // [__first, __last) all equivalent elements + } + if (__comp(*__first, *__i)) + { swap(*__i, *__j); ++__n_swaps; - // It is known that __m != __j - // If __m just moved, follow it - if (__m == __i) - __m = __j; ++__i; + break; + } + ++__i; } - } - // [__first, __i) < *__m and *__m <= [__i, __last) - if (__i != __m && __comp(*__m, *__i)) - { - swap(*__i, *__m); - ++__n_swaps; - } - // [__first, __i) < *__i and *__i <= [__i+1, __last) - if (__nth == __i) + } + // [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1 + if (__i == __j) + { return; - if (__n_swaps == 0) - { - // We were given a perfectly partitioned sequence. Coincidence? - if (__nth < __i) + } + while (true) + { + while (!__comp(*__first, *__i)) { - // Check for [__first, __i) already sorted - __j = __m = __first; - while (++__j != __i) - { - if (__comp(*__j, *__m)) - // not yet sorted, so sort - goto not_sorted; - __m = __j; - } - // [__first, __i) sorted - return; + ++__i; } - else + while (__comp(*__first, *--__j)) + ; + if (__i >= __j) { - // Check for [__i, __last) already sorted - __j = __m = __i; - while (++__j != __last) - { - if (__comp(*__j, *__m)) - // not yet sorted, so sort - goto not_sorted; - __m = __j; - } - // [__i, __last) sorted - return; + break; } + swap(*__i, *__j); + ++__n_swaps; + ++__i; + } + // [__first, __i) == *__first and *__first < [__i, __last) + // The first part is sorted, + if (__nth < __i) + { + return; + } + // __nth_element the secod part + // __nth_element<_Compare>(__i, __nth, __last, __comp); + __first = __i; + goto __restart; + } + if (__comp(*__j, *__m)) + { + swap(*__i, *__j); + ++__n_swaps; + break; // found guard for downward moving __j, now use unguarded partition + } + } + } + ++__i; + // j points beyond range to be tested, *__lm1 is known to be <= *__m + // if not yet partitioned... + if (__i < __j) + { + // known that *(__i - 1) < *__m + while (true) + { + // __m still guards upward moving __i + while (__comp(*__i, *__m)) + { + ++__i; + } + // It is now known that a guard exists for downward moving __j + while (!__comp(*--__j, *__m)) + ; + if (__i >= __j) + { + break; + } + swap(*__i, *__j); + ++__n_swaps; + // It is known that __m != __j + // If __m just moved, follow it + if (__m == __i) + { + __m = __j; } -not_sorted: - // __nth_element on range containing __nth - if (__nth < __i) + ++__i; + } + } + // [__first, __i) < *__m and *__m <= [__i, __last) + if (__i != __m && __comp(*__m, *__i)) + { + swap(*__i, *__m); + ++__n_swaps; + } + // [__first, __i) < *__i and *__i <= [__i+1, __last) + if (__nth == __i) + { + return; + } + if (__n_swaps == 0) + { + // We were given a perfectly partitioned sequence. Coincidence? + if (__nth < __i) + { + // Check for [__first, __i) already sorted + __j = __m = __first; + while (++__j != __i) { - // __nth_element<_Compare>(__first, __nth, __i, __comp); - __last = __i; + if (__comp(*__j, *__m)) + { + // not yet sorted, so sort + goto not_sorted; + } + __m = __j; } - else + // [__first, __i) sorted + return; + } + else + { + // Check for [__i, __last) already sorted + __j = __m = __i; + while (++__j != __last) { - // __nth_element<_Compare>(__i+1, __nth, __last, __comp); - __first = ++__i; + if (__comp(*__j, *__m)) + { + // not yet sorted, so sort + goto not_sorted; + } + __m = __j; } + // [__i, __last) sorted + return; + } + } + not_sorted: + // __nth_element on range containing __nth + if (__nth < __i) + { + // __nth_element<_Compare>(__first, __nth, __i, __comp); + __last = __i; } + else + { + // __nth_element<_Compare>(__i+1, __nth, __last, __comp); + __first = ++__i; + } + } } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void +inline _LIBCUDACXX_INLINE_VISIBILITY void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { - using _Comp_ref = __comp_ref_type<_Compare>; - __nth_element<_Comp_ref>(__first, __nth, __last, __comp); + using _Comp_ref = __comp_ref_type<_Compare>; + __nth_element<_Comp_ref>(__first, __nth, __last, __comp); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -void +inline _LIBCUDACXX_INLINE_VISIBILITY void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) { - _CUDA_VSTD::nth_element(__first, __nth, __last, __less{}); + _CUDA_VSTD::nth_element(__first, __nth, __last, __less{}); } #endif _LIBCUDACXX_END_NAMESPACE_STD #if defined(_LIBCUDACXX_HAS_PARALLEL_ALGORITHMS) && _CCCL_STD_VER >= 2017 -# include <__pstl_algorithm> +# include <__pstl_algorithm> #endif #include -#endif // _LIBCUDACXX_ALGORITHM +#endif // _LIBCUDACXX_ALGORITHM diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/array b/libcudacxx/include/cuda/std/detail/libcxx/include/array index 5e1a0429d42..82223dd3abd 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/array +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/array @@ -123,7 +123,6 @@ template const T&& get(const array&&) noexce #include #include #include -#include // all public C++ headers provide the assertion handler #include #include #include @@ -139,10 +138,10 @@ template const T&& get(const array&&) noexce #include #include #include +#include +#include // all public C++ headers provide the assertion handler #include #include - -#include #include // standard-mandated includes @@ -192,8 +191,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array _CUDA_VSTD::fill_n(__elems_, _Size, __u); } - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 void - swap(array& __a) noexcept(__is_nothrow_swappable<_Tp>::value) + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 void swap(array& __a) noexcept(__is_nothrow_swappable<_Tp>::value) { _CUDA_VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.data()); } @@ -203,8 +201,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array { return iterator(__elems_); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - begin() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator begin() const noexcept { return const_iterator(__elems_); } @@ -212,14 +209,12 @@ struct _LIBCUDACXX_TEMPLATE_VIS array { return iterator(__elems_ + _Size); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - end() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator end() const noexcept { return const_iterator(__elems_ + _Size); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator - rbegin() noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator rbegin() noexcept { return reverse_iterator(end()); } @@ -228,8 +223,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array { return const_reverse_iterator(end()); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator - rend() noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator rend() noexcept { return reverse_iterator(begin()); } @@ -239,13 +233,11 @@ struct _LIBCUDACXX_TEMPLATE_VIS array return const_reverse_iterator(begin()); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - cbegin() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator cbegin() const noexcept { return begin(); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - cend() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator cend() const noexcept { return end(); } @@ -297,8 +289,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array return __elems_[__n]; } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference - at(size_type __n) const + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference at(size_type __n) const { if (__n >= _Size) { @@ -311,8 +302,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array { return (*this)[0]; } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference - front() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference front() const noexcept { return (*this)[0]; } @@ -320,8 +310,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array { return (*this)[_Size - 1]; } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference - back() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference back() const noexcept { return (*this)[_Size - 1]; } @@ -330,8 +319,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array { return __elems_; } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const value_type* - data() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const value_type* data() const noexcept { return __elems_; } @@ -366,8 +354,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array<_Tp, 0> { return nullptr; } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const value_type* - data() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const value_type* data() const noexcept { return nullptr; } @@ -388,8 +375,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array<_Tp, 0> { return iterator(nullptr); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - begin() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator begin() const noexcept { return const_iterator(nullptr); } @@ -397,14 +383,12 @@ struct _LIBCUDACXX_TEMPLATE_VIS array<_Tp, 0> { return iterator(nullptr); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - end() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator end() const noexcept { return const_iterator(nullptr); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator - rbegin() noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator rbegin() noexcept { return reverse_iterator(end()); } @@ -413,8 +397,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS array<_Tp, 0> { return const_reverse_iterator(end()); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator - rend() noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 reverse_iterator rend() noexcept { return reverse_iterator(begin()); } @@ -424,13 +407,11 @@ struct _LIBCUDACXX_TEMPLATE_VIS array<_Tp, 0> return const_reverse_iterator(begin()); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - cbegin() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator cbegin() const noexcept { return begin(); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator - cend() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_iterator cend() const noexcept { return end(); } @@ -459,11 +440,10 @@ struct _LIBCUDACXX_TEMPLATE_VIS array<_Tp, 0> return true; } -_CCCL_DIAG_PUSH -_CCCL_DIAG_SUPPRESS_MSVC(4702) // Unreachable code + _CCCL_DIAG_PUSH + _CCCL_DIAG_SUPPRESS_MSVC(4702) // Unreachable code // element access: - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 reference - operator[](size_type) noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 reference operator[](size_type) noexcept { _LIBCUDACXX_ASSERT(false, "cannot call array::operator[] on a zero-sized array"); _LIBCUDACXX_UNREACHABLE(); @@ -484,8 +464,7 @@ _CCCL_DIAG_SUPPRESS_MSVC(4702) // Unreachable code _LIBCUDACXX_UNREACHABLE(); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference - at(size_type) const + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference at(size_type) const { __throw_out_of_range("array::at"); _LIBCUDACXX_UNREACHABLE(); @@ -498,8 +477,7 @@ _CCCL_DIAG_SUPPRESS_MSVC(4702) // Unreachable code return *data(); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference - front() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference front() const noexcept { _LIBCUDACXX_ASSERT(false, "cannot call array::front() on a zero-sized array"); _LIBCUDACXX_UNREACHABLE(); @@ -513,18 +491,17 @@ _CCCL_DIAG_SUPPRESS_MSVC(4702) // Unreachable code return *data(); } - _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference - back() const noexcept + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const_reference back() const noexcept { _LIBCUDACXX_ASSERT(false, "cannot call array::back() on a zero-sized array"); _LIBCUDACXX_UNREACHABLE(); return *data(); } -_CCCL_DIAG_POP + _CCCL_DIAG_POP }; #if _CCCL_STD_VER >= 2017 -template && ...)> > +template && ...)>> _CCCL_HOST_DEVICE array(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>; #endif // _CCCL_STD_VER >= 2017 @@ -571,19 +548,18 @@ operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y) } template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - __enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, void> - swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) noexcept(noexcept(__x.swap(__y))) +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __enable_if_t<_Size == 0 || __is_swappable<_Tp>::value, void> +swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y) noexcept(noexcept(__x.swap(__y))) { __x.swap(__y); } template -struct _LIBCUDACXX_TEMPLATE_VIS tuple_size > : public integral_constant +struct _LIBCUDACXX_TEMPLATE_VIS tuple_size> : public integral_constant {}; template -struct _LIBCUDACXX_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > +struct _LIBCUDACXX_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size>> { static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); typedef _Tp type; @@ -597,8 +573,7 @@ inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp& get(array<_Tp, _ } template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Tp& -get(const array<_Tp, _Size>& __a) noexcept +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Tp& get(const array<_Tp, _Size>& __a) noexcept { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)"); return __a.__elems_[_Ip]; @@ -612,8 +587,7 @@ inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp&& get(array<_Tp, } template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Tp&& -get(const array<_Tp, _Size>&& __a) noexcept +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Tp&& get(const array<_Tp, _Size>&& __a) noexcept { static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); return _CUDA_VSTD::move(__a.__elems_[_Ip]); diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/barrier b/libcudacxx/include/cuda/std/detail/libcxx/include/barrier index 4127fe75266..42b8ec72912 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/barrier +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/barrier @@ -53,416 +53,405 @@ namespace std # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler -#include -#include #include #include #include +#include // all public C++ headers provide the assertion handler +#include +#include #include #ifdef _LIBCUDACXX_HAS_NO_THREADS -# error is not supported on this single threaded system +# error is not supported on this single threaded system #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD struct __empty_completion { - inline _LIBCUDACXX_INLINE_VISIBILITY - void operator()() noexcept { } + inline _LIBCUDACXX_INLINE_VISIBILITY void operator()() noexcept {} }; #ifndef _LIBCUDACXX_HAS_NO_TREE_BARRIER -template -class alignas(64) __barrier_base { - - ptrdiff_t __expected; - __atomic_base __expected_adjustment; - _CompletionF __completion; +template +class alignas(64) __barrier_base +{ + ptrdiff_t __expected; + __atomic_base __expected_adjustment; + _CompletionF __completion; - using __phase_t = uint8_t; - __atomic_base<__phase_t, _Sco> __phase; + using __phase_t = uint8_t; + __atomic_base<__phase_t, _Sco> __phase; - struct alignas(64) __state_t + struct alignas(64) __state_t + { + struct { - struct { - __atomic_base<__phase_t, _Sco> __phase = ATOMIC_VAR_INIT(0); - } __tickets[64]; - }; - ::std::vector<__state_t> __state; - - inline _LIBCUDACXX_INLINE_VISIBILITY - bool __arrive(__phase_t const __old_phase) + __atomic_base<__phase_t, _Sco> __phase = ATOMIC_VAR_INIT(0); + } __tickets[64]; + }; + ::std::vector<__state_t> __state; + + inline _LIBCUDACXX_INLINE_VISIBILITY bool __arrive(__phase_t const __old_phase) + { + __phase_t const __half_step = __old_phase + 1, __full_step = __old_phase + 2; +# ifndef _LIBCUDACXX_HAS_NO_THREAD_FAVORITE_BARRIER_INDEX + ptrdiff_t __current = __libcpp_thread_favorite_barrier_index, +# else + ptrdiff_t __current = 0, +# endif + __current_expected = __expected, __last_node = (__current_expected >> 1); + for (size_t __round = 0;; ++__round) { - __phase_t const __half_step = __old_phase + 1, __full_step = __old_phase + 2; -#ifndef _LIBCUDACXX_HAS_NO_THREAD_FAVORITE_BARRIER_INDEX - ptrdiff_t __current = __libcpp_thread_favorite_barrier_index, -#else - ptrdiff_t __current = 0, -#endif - __current_expected = __expected, - __last_node = (__current_expected >> 1); - for(size_t __round = 0;; ++__round) { - _LIBCUDACXX_ASSERT(__round <= 63, ""); - if(__current_expected == 1) - return true; - for(;;++__current) { -#ifndef _LIBCUDACXX_HAS_NO_THREAD_FAVORITE_BARRIER_INDEX - if(0 == __round) { - if(__current >= __current_expected) - __current = 0; - __libcpp_thread_favorite_barrier_index = __current; - } -#endif - _LIBCUDACXX_ASSERT(__current <= __last_node, ""); - __phase_t expect = __old_phase; - if(__current == __last_node && (__current_expected & 1)) - { - if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __full_step, memory_order_acq_rel)) - break; // I'm 1 in 1, go to next __round - _LIBCUDACXX_ASSERT(expect == __full_step, ""); - } - else if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __half_step, memory_order_acq_rel)) - { - return false; // I'm 1 in 2, done with arrival - } - else if(expect == __half_step) - { - if(__state[__current].__tickets[__round].__phase.compare_exchange_strong(expect, __full_step, memory_order_acq_rel)) - break; // I'm 2 in 2, go to next __round - _LIBCUDACXX_ASSERT(expect == __full_step, ""); - } - _LIBCUDACXX_ASSERT(__round == 0 && expect == __full_step, ""); - } - __current_expected = (__current_expected >> 1) + (__current_expected & 1); - __current &= ~( 1 << __round ); - __last_node &= ~( 1 << __round ); + _LIBCUDACXX_ASSERT(__round <= 63, ""); + if (__current_expected == 1) + { + return true; + } + for (;; ++__current) + { +# ifndef _LIBCUDACXX_HAS_NO_THREAD_FAVORITE_BARRIER_INDEX + if (0 == __round) + { + if (__current >= __current_expected) + { + __current = 0; + } + __libcpp_thread_favorite_barrier_index = __current; + } +# endif + _LIBCUDACXX_ASSERT(__current <= __last_node, ""); + __phase_t expect = __old_phase; + if (__current == __last_node && (__current_expected & 1)) + { + if (__state[__current].__tickets[__round].__phase.compare_exchange_strong( + expect, __full_step, memory_order_acq_rel)) + { + break; // I'm 1 in 1, go to next __round + } + _LIBCUDACXX_ASSERT(expect == __full_step, ""); + } + else if (__state[__current].__tickets[__round].__phase.compare_exchange_strong( + expect, __half_step, memory_order_acq_rel)) + { + return false; // I'm 1 in 2, done with arrival } + else if (expect == __half_step) + { + if (__state[__current].__tickets[__round].__phase.compare_exchange_strong( + expect, __full_step, memory_order_acq_rel)) + { + break; // I'm 2 in 2, go to next __round + } + _LIBCUDACXX_ASSERT(expect == __full_step, ""); + } + _LIBCUDACXX_ASSERT(__round == 0 && expect == __full_step, ""); + } + __current_expected = (__current_expected >> 1) + (__current_expected & 1); + __current &= ~(1 << __round); + __last_node &= ~(1 << __round); } + } public: - using arrival_token = __phase_t; - - inline _LIBCUDACXX_INLINE_VISIBILITY - __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF()) - : __expected(__expected), __expected_adjustment(0), __completion(__completion), - __phase(0), __state((__expected+1) >> 1) - { - _LIBCUDACXX_ASSERT(__expected >= 0, ""); - } + using arrival_token = __phase_t; + + inline _LIBCUDACXX_INLINE_VISIBILITY __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF()) + : __expected(__expected) + , __expected_adjustment(0) + , __completion(__completion) + , __phase(0) + , __state((__expected + 1) >> 1) + { + _LIBCUDACXX_ASSERT(__expected >= 0, ""); + } - inline _LIBCUDACXX_INLINE_VISIBILITY - ~__barrier_base() = default; + inline _LIBCUDACXX_INLINE_VISIBILITY ~__barrier_base() = default; - __barrier_base(__barrier_base const&) = delete; - __barrier_base& operator=(__barrier_base const&) = delete; + __barrier_base(__barrier_base const&) = delete; + __barrier_base& operator=(__barrier_base const&) = delete; - _CCCL_NODISCARD inline _LIBCUDACXX_INLINE_VISIBILITY - arrival_token arrive(ptrdiff_t update = 1) - { - _LIBCUDACXX_ASSERT(update > 0, ""); - auto __old_phase = __phase.load(memory_order_relaxed); - for(; update; --update) - if(__arrive(__old_phase)) { - __completion(); - __expected += __expected_adjustment.load(memory_order_relaxed); - __expected_adjustment.store(0, memory_order_relaxed); - __phase.store(__old_phase + 2, memory_order_release); - } - return __old_phase; - } - inline _LIBCUDACXX_INLINE_VISIBILITY - void wait(arrival_token&& __old_phase) const - { - __libcpp_thread_poll_with_backoff([=]() -> bool { - return __phase.load(memory_order_acquire) != __old_phase; - }); - } - inline _LIBCUDACXX_INLINE_VISIBILITY - void arrive_and_wait() - { - wait(arrive()); - } - inline _LIBCUDACXX_INLINE_VISIBILITY - void arrive_and_drop() + _CCCL_NODISCARD inline _LIBCUDACXX_INLINE_VISIBILITY arrival_token arrive(ptrdiff_t update = 1) + { + _LIBCUDACXX_ASSERT(update > 0, ""); + auto __old_phase = __phase.load(memory_order_relaxed); + for (; update; --update) { - __expected_adjustment.fetch_sub(1, memory_order_relaxed); - (void)arrive(); + if (__arrive(__old_phase)) + { + __completion(); + __expected += __expected_adjustment.load(memory_order_relaxed); + __expected_adjustment.store(0, memory_order_relaxed); + __phase.store(__old_phase + 2, memory_order_release); + } } + return __old_phase; + } + inline _LIBCUDACXX_INLINE_VISIBILITY void wait(arrival_token&& __old_phase) const + { + __libcpp_thread_poll_with_backoff([=]() -> bool { + return __phase.load(memory_order_acquire) != __old_phase; + }); + } + inline _LIBCUDACXX_INLINE_VISIBILITY void arrive_and_wait() + { + wait(arrive()); + } + inline _LIBCUDACXX_INLINE_VISIBILITY void arrive_and_drop() + { + __expected_adjustment.fetch_sub(1, memory_order_relaxed); + (void) arrive(); + } }; #else -# if _LIBCUDACXX_CUDA_ABI_VERSION < 3 -# define _LIBCUDACXX_BARRIER_ALIGNMENTS alignas(64) -# else -# define _LIBCUDACXX_BARRIER_ALIGNMENTS -# endif +# if _LIBCUDACXX_CUDA_ABI_VERSION < 3 +# define _LIBCUDACXX_BARRIER_ALIGNMENTS alignas(64) +# else +# define _LIBCUDACXX_BARRIER_ALIGNMENTS +# endif -template -class __barrier_poll_tester_phase { - _Barrier const* __this; - typename _Barrier::arrival_token __phase; +template +class __barrier_poll_tester_phase +{ + _Barrier const* __this; + typename _Barrier::arrival_token __phase; public: - _LIBCUDACXX_INLINE_VISIBILITY - __barrier_poll_tester_phase(_Barrier const* __this_, - typename _Barrier::arrival_token&& __phase_) - : __this(__this_) - , __phase(_CUDA_VSTD::move(__phase_)) - {} - - _LIBCUDACXX_INLINE_VISIBILITY - bool operator()() const - { - return __this->__try_wait(__phase); - } + _LIBCUDACXX_INLINE_VISIBILITY + __barrier_poll_tester_phase(_Barrier const* __this_, typename _Barrier::arrival_token&& __phase_) + : __this(__this_) + , __phase(_CUDA_VSTD::move(__phase_)) + {} + + _LIBCUDACXX_INLINE_VISIBILITY bool operator()() const + { + return __this->__try_wait(__phase); + } }; -template -class __barrier_poll_tester_parity { - _Barrier const* __this; - bool __parity; +template +class __barrier_poll_tester_parity +{ + _Barrier const* __this; + bool __parity; public: - _LIBCUDACXX_INLINE_VISIBILITY - __barrier_poll_tester_parity(_Barrier const* __this_, bool __parity_) - : __this(__this_) - , __parity(__parity_) - {} - - inline _LIBCUDACXX_INLINE_VISIBILITY - bool operator()() const - { - return __this->__try_wait_parity(__parity); - } + _LIBCUDACXX_INLINE_VISIBILITY __barrier_poll_tester_parity(_Barrier const* __this_, bool __parity_) + : __this(__this_) + , __parity(__parity_) + {} + + inline _LIBCUDACXX_INLINE_VISIBILITY bool operator()() const + { + return __this->__try_wait_parity(__parity); + } }; -template -_LIBCUDACXX_INLINE_VISIBILITY -bool __call_try_wait(const _Barrier& __b, typename _Barrier::arrival_token&& __phase) +template +_LIBCUDACXX_INLINE_VISIBILITY bool __call_try_wait(const _Barrier& __b, typename _Barrier::arrival_token&& __phase) { - return __b.__try_wait(_CUDA_VSTD::move(__phase)); + return __b.__try_wait(_CUDA_VSTD::move(__phase)); } -template -_LIBCUDACXX_INLINE_VISIBILITY -bool __call_try_wait_parity(const _Barrier& __b, bool __parity) +template +_LIBCUDACXX_INLINE_VISIBILITY bool __call_try_wait_parity(const _Barrier& __b, bool __parity) { - return __b.__try_wait_parity(__parity); + return __b.__try_wait_parity(__parity); } - -template -class __barrier_base { - - _LIBCUDACXX_BARRIER_ALIGNMENTS __atomic_base __expected, __arrived; - _LIBCUDACXX_BARRIER_ALIGNMENTS _CompletionF __completion; - _LIBCUDACXX_BARRIER_ALIGNMENTS __atomic_base __phase; +template +class __barrier_base +{ + _LIBCUDACXX_BARRIER_ALIGNMENTS __atomic_base __expected, __arrived; + _LIBCUDACXX_BARRIER_ALIGNMENTS _CompletionF __completion; + _LIBCUDACXX_BARRIER_ALIGNMENTS __atomic_base __phase; public: - using arrival_token = bool; + using arrival_token = bool; private: - template - friend class __barrier_poll_tester_phase; - template - friend class __barrier_poll_tester_parity; - template - _LIBCUDACXX_INLINE_VISIBILITY - friend bool __call_try_wait(const _Barrier& __b, - typename _Barrier::arrival_token&& __phase); - template - _LIBCUDACXX_INLINE_VISIBILITY - friend bool __call_try_wait_parity(const _Barrier& __b, bool __parity); - - _LIBCUDACXX_INLINE_VISIBILITY - bool __try_wait(arrival_token __old) const - { - return __phase.load(memory_order_acquire) != __old; - } - _LIBCUDACXX_INLINE_VISIBILITY - bool __try_wait_parity(bool __parity) const - { - return __try_wait(__parity); - } + template + friend class __barrier_poll_tester_phase; + template + friend class __barrier_poll_tester_parity; + template + _LIBCUDACXX_INLINE_VISIBILITY friend bool + __call_try_wait(const _Barrier& __b, typename _Barrier::arrival_token&& __phase); + template + _LIBCUDACXX_INLINE_VISIBILITY friend bool __call_try_wait_parity(const _Barrier& __b, bool __parity); + + _LIBCUDACXX_INLINE_VISIBILITY bool __try_wait(arrival_token __old) const + { + return __phase.load(memory_order_acquire) != __old; + } + _LIBCUDACXX_INLINE_VISIBILITY bool __try_wait_parity(bool __parity) const + { + return __try_wait(__parity); + } public: - __barrier_base() = default; + __barrier_base() = default; - _LIBCUDACXX_INLINE_VISIBILITY - __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF()) - : __expected(__expected), __arrived(__expected), __completion(__completion), __phase(false) - { - } + _LIBCUDACXX_INLINE_VISIBILITY __barrier_base(ptrdiff_t __expected, _CompletionF __completion = _CompletionF()) + : __expected(__expected) + , __arrived(__expected) + , __completion(__completion) + , __phase(false) + {} - ~__barrier_base() = default; + ~__barrier_base() = default; - __barrier_base(__barrier_base const&) = delete; - __barrier_base& operator=(__barrier_base const&) = delete; + __barrier_base(__barrier_base const&) = delete; + __barrier_base& operator=(__barrier_base const&) = delete; - _CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY - arrival_token arrive(ptrdiff_t __update = 1) - { - auto const __old_phase = __phase.load(memory_order_relaxed); - auto const __result = __arrived.fetch_sub(__update, memory_order_acq_rel) - __update; - auto const __new_expected = __expected.load(memory_order_relaxed); + _CCCL_NODISCARD _LIBCUDACXX_INLINE_VISIBILITY arrival_token arrive(ptrdiff_t __update = 1) + { + auto const __old_phase = __phase.load(memory_order_relaxed); + auto const __result = __arrived.fetch_sub(__update, memory_order_acq_rel) - __update; + auto const __new_expected = __expected.load(memory_order_relaxed); - _LIBCUDACXX_DEBUG_ASSERT(__result >= 0, ""); + _LIBCUDACXX_DEBUG_ASSERT(__result >= 0, ""); - if(0 == __result) { - __completion(); - __arrived.store(__new_expected, memory_order_relaxed); - __phase.store(!__old_phase, memory_order_release); - __cxx_atomic_notify_all(&__phase.__a_); - } - return __old_phase; - } - _LIBCUDACXX_INLINE_VISIBILITY - void wait(arrival_token&& __old_phase) const + if (0 == __result) { - __phase.wait(__old_phase, memory_order_acquire); - } - _LIBCUDACXX_INLINE_VISIBILITY - void arrive_and_wait() - { - wait(arrive()); - } - _LIBCUDACXX_INLINE_VISIBILITY - void arrive_and_drop() - { - __expected.fetch_sub(1, memory_order_relaxed); - (void)arrive(); + __completion(); + __arrived.store(__new_expected, memory_order_relaxed); + __phase.store(!__old_phase, memory_order_release); + __cxx_atomic_notify_all(&__phase.__a_); } + return __old_phase; + } + _LIBCUDACXX_INLINE_VISIBILITY void wait(arrival_token&& __old_phase) const + { + __phase.wait(__old_phase, memory_order_acquire); + } + _LIBCUDACXX_INLINE_VISIBILITY void arrive_and_wait() + { + wait(arrive()); + } + _LIBCUDACXX_INLINE_VISIBILITY void arrive_and_drop() + { + __expected.fetch_sub(1, memory_order_relaxed); + (void) arrive(); + } - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr ptrdiff_t max() noexcept - { - return numeric_limits::max(); - } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr ptrdiff_t max() noexcept + { + return numeric_limits::max(); + } }; -template -class __barrier_base<__empty_completion, _Sco> { - - static constexpr uint64_t __expected_unit = 1ull; - static constexpr uint64_t __arrived_unit = 1ull << 32; - static constexpr uint64_t __expected_mask = __arrived_unit - 1; - static constexpr uint64_t __phase_bit = 1ull << 63; - static constexpr uint64_t __arrived_mask = (__phase_bit - 1) & ~__expected_mask; +template +class __barrier_base<__empty_completion, _Sco> +{ + static constexpr uint64_t __expected_unit = 1ull; + static constexpr uint64_t __arrived_unit = 1ull << 32; + static constexpr uint64_t __expected_mask = __arrived_unit - 1; + static constexpr uint64_t __phase_bit = 1ull << 63; + static constexpr uint64_t __arrived_mask = (__phase_bit - 1) & ~__expected_mask; - _LIBCUDACXX_BARRIER_ALIGNMENTS __atomic_base __phase_arrived_expected; + _LIBCUDACXX_BARRIER_ALIGNMENTS __atomic_base __phase_arrived_expected; public: - using arrival_token = uint64_t; + using arrival_token = uint64_t; private: - template - friend class __barrier_poll_tester_phase; - template - friend class __barrier_poll_tester_parity; - template - _LIBCUDACXX_INLINE_VISIBILITY - friend bool __call_try_wait(const _Barrier& __b, - typename _Barrier::arrival_token&& __phase); - template - _LIBCUDACXX_INLINE_VISIBILITY - friend bool __call_try_wait_parity(const _Barrier& __b, bool __parity); - - static _LIBCUDACXX_INLINE_VISIBILITY constexpr - uint64_t __init(ptrdiff_t __count) noexcept - { -#if _CCCL_STD_VER > 2011 - // This debug assert is not supported in C++11 due to resulting in a - // multi-statement constexpr function. - _LIBCUDACXX_DEBUG_ASSERT(__count >= 0, "Count must be non-negative."); -#endif // _CCCL_STD_VER > 2011 - return (((1u << 31) - __count) << 32) - | ((1u << 31) - __count); - } - _LIBCUDACXX_INLINE_VISIBILITY - bool __try_wait_phase(uint64_t __phase) const - { - uint64_t const __current = __phase_arrived_expected.load(memory_order_acquire); - return ((__current & __phase_bit) != __phase); - } - _LIBCUDACXX_INLINE_VISIBILITY - bool __try_wait(arrival_token __old) const - { - return __try_wait_phase(__old & __phase_bit); - } - _LIBCUDACXX_INLINE_VISIBILITY - bool __try_wait_parity(bool __parity) const - { - return __try_wait_phase(__parity ? __phase_bit : 0); - } + template + friend class __barrier_poll_tester_phase; + template + friend class __barrier_poll_tester_parity; + template + _LIBCUDACXX_INLINE_VISIBILITY friend bool + __call_try_wait(const _Barrier& __b, typename _Barrier::arrival_token&& __phase); + template + _LIBCUDACXX_INLINE_VISIBILITY friend bool __call_try_wait_parity(const _Barrier& __b, bool __parity); + + static _LIBCUDACXX_INLINE_VISIBILITY constexpr uint64_t __init(ptrdiff_t __count) noexcept + { +# if _CCCL_STD_VER > 2011 + // This debug assert is not supported in C++11 due to resulting in a + // multi-statement constexpr function. + _LIBCUDACXX_DEBUG_ASSERT(__count >= 0, "Count must be non-negative."); +# endif // _CCCL_STD_VER > 2011 + return (((1u << 31) - __count) << 32) | ((1u << 31) - __count); + } + _LIBCUDACXX_INLINE_VISIBILITY bool __try_wait_phase(uint64_t __phase) const + { + uint64_t const __current = __phase_arrived_expected.load(memory_order_acquire); + return ((__current & __phase_bit) != __phase); + } + _LIBCUDACXX_INLINE_VISIBILITY bool __try_wait(arrival_token __old) const + { + return __try_wait_phase(__old & __phase_bit); + } + _LIBCUDACXX_INLINE_VISIBILITY bool __try_wait_parity(bool __parity) const + { + return __try_wait_phase(__parity ? __phase_bit : 0); + } public: - __barrier_base() = default; + __barrier_base() = default; - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - __barrier_base(ptrdiff_t __count, __empty_completion = __empty_completion()) - : __phase_arrived_expected(__init(__count)) { - _LIBCUDACXX_DEBUG_ASSERT(__count >= 0, ""); - } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 + __barrier_base(ptrdiff_t __count, __empty_completion = __empty_completion()) + : __phase_arrived_expected(__init(__count)) + { + _LIBCUDACXX_DEBUG_ASSERT(__count >= 0, ""); + } - ~__barrier_base() = default; + ~__barrier_base() = default; - __barrier_base(__barrier_base const&) = delete; - __barrier_base& operator=(__barrier_base const&) = delete; + __barrier_base(__barrier_base const&) = delete; + __barrier_base& operator=(__barrier_base const&) = delete; - _CCCL_NODISCARD inline _LIBCUDACXX_INLINE_VISIBILITY - arrival_token arrive(ptrdiff_t __update = 1) - { - auto const __inc = __arrived_unit * __update; - auto const __old = __phase_arrived_expected.fetch_add(__inc, memory_order_acq_rel); - if((__old ^ (__old + __inc)) & __phase_bit) { - __phase_arrived_expected.fetch_add((__old & __expected_mask) << 32, memory_order_relaxed); - __phase_arrived_expected.notify_all(); - } - return __old & __phase_bit; - } - _LIBCUDACXX_INLINE_VISIBILITY - void wait(arrival_token&& __phase) const - { - __libcpp_thread_poll_with_backoff(__barrier_poll_tester_phase<__barrier_base>(this, _CUDA_VSTD::move(__phase))); - } - _LIBCUDACXX_INLINE_VISIBILITY - void wait_parity(bool __parity) const - { - __libcpp_thread_poll_with_backoff(__barrier_poll_tester_parity<__barrier_base>(this, __parity)); - } - _LIBCUDACXX_INLINE_VISIBILITY - void arrive_and_wait() - { - wait(arrive()); - } - _LIBCUDACXX_INLINE_VISIBILITY - void arrive_and_drop() + _CCCL_NODISCARD inline _LIBCUDACXX_INLINE_VISIBILITY arrival_token arrive(ptrdiff_t __update = 1) + { + auto const __inc = __arrived_unit * __update; + auto const __old = __phase_arrived_expected.fetch_add(__inc, memory_order_acq_rel); + if ((__old ^ (__old + __inc)) & __phase_bit) { - __phase_arrived_expected.fetch_add(__expected_unit, memory_order_relaxed); - (void)arrive(); + __phase_arrived_expected.fetch_add((__old & __expected_mask) << 32, memory_order_relaxed); + __phase_arrived_expected.notify_all(); } + return __old & __phase_bit; + } + _LIBCUDACXX_INLINE_VISIBILITY void wait(arrival_token&& __phase) const + { + __libcpp_thread_poll_with_backoff(__barrier_poll_tester_phase<__barrier_base>(this, _CUDA_VSTD::move(__phase))); + } + _LIBCUDACXX_INLINE_VISIBILITY void wait_parity(bool __parity) const + { + __libcpp_thread_poll_with_backoff(__barrier_poll_tester_parity<__barrier_base>(this, __parity)); + } + _LIBCUDACXX_INLINE_VISIBILITY void arrive_and_wait() + { + wait(arrive()); + } + _LIBCUDACXX_INLINE_VISIBILITY void arrive_and_drop() + { + __phase_arrived_expected.fetch_add(__expected_unit, memory_order_relaxed); + (void) arrive(); + } - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr ptrdiff_t max() noexcept - { - return numeric_limits::max(); - } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr ptrdiff_t max() noexcept + { + return numeric_limits::max(); + } }; #endif //_LIBCUDACXX_HAS_NO_TREE_BARRIER -template -class barrier : public __barrier_base<_CompletionF> { +template +class barrier : public __barrier_base<_CompletionF> +{ public: - _LIBCUDACXX_INLINE_VISIBILITY constexpr - barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF()) - : __barrier_base<_CompletionF>(__count, __completion) { - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF()) + : __barrier_base<_CompletionF>(__count, __completion) + {} }; _LIBCUDACXX_END_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/bit b/libcudacxx/include/cuda/std/detail/libcxx/include/bit index ae31988c7c6..854a1ac6683 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/bit +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/bit @@ -63,9 +63,9 @@ namespace std { # pragma system_header #endif // no system header +#include #include // all public C++ headers provide the assertion handler #include -#include #include #include #include @@ -73,800 +73,741 @@ namespace std { #include #if defined(_CCCL_COMPILER_MSVC) -#include +# include #endif // _CCCL_COMPILER_MSVC #if defined(_CCCL_COMPILER_IBM) -#include +# include #endif // _CCCL_COMPILER_IBM _LIBCUDACXX_BEGIN_NAMESPACE_STD #define _LIBCUDACXX_BIT_CONSTEXPR constexpr -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_ctz2(uint64_t __x, int __c) noexcept { +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_ctz2(uint64_t __x, int __c) noexcept +{ return (__x & 0x1) ? __c : __c + 1; } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_ctz4(uint64_t __x, int __c) noexcept { - return __binary_ctz2( - __x >> 2*!(__x & 0x3), - __c + 2*!(__x & 0x3)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_ctz4(uint64_t __x, int __c) noexcept +{ + return __binary_ctz2(__x >> 2 * !(__x & 0x3), __c + 2 * !(__x & 0x3)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_ctz8(uint64_t __x, int __c) noexcept { - return __binary_ctz4( - __x >> 4*!(__x & 0x0F), - __c + 4*!(__x & 0x0F)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_ctz8(uint64_t __x, int __c) noexcept +{ + return __binary_ctz4(__x >> 4 * !(__x & 0x0F), __c + 4 * !(__x & 0x0F)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_ctz16(uint64_t __x, int __c) noexcept { - return __binary_ctz8( - __x >> 8*!(__x & 0x00FF), - __c + 8*!(__x & 0x00FF)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_ctz16(uint64_t __x, int __c) noexcept +{ + return __binary_ctz8(__x >> 8 * !(__x & 0x00FF), __c + 8 * !(__x & 0x00FF)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_ctz32(uint64_t __x, int __c) noexcept { - return __binary_ctz16( - __x >> 16*!(__x & 0x0000FFFF), - __c + 16*!(__x & 0x0000FFFF)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_ctz32(uint64_t __x, int __c) noexcept +{ + return __binary_ctz16(__x >> 16 * !(__x & 0x0000FFFF), __c + 16 * !(__x & 0x0000FFFF)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_ctz64(uint64_t __x) noexcept { - return __binary_ctz32( - __x >> 32*!(__x & 0x00000000FFFFFFFF), - 32*!(__x & 0x00000000FFFFFFFF)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_ctz64(uint64_t __x) noexcept +{ + return __binary_ctz32(__x >> 32 * !(__x & 0x00000000FFFFFFFF), 32 * !(__x & 0x00000000FFFFFFFF)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_clz2(uint64_t __x, int __c) { +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_clz2(uint64_t __x, int __c) +{ return !!(~__x & 0x2) ^ __c; } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_clz4(uint64_t __x, int __c) { - return __binary_clz2( - __x >> 2*!!(__x & 0xC), - __c + 2*!(__x & 0xC)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_clz4(uint64_t __x, int __c) +{ + return __binary_clz2(__x >> 2 * !!(__x & 0xC), __c + 2 * !(__x & 0xC)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_clz8(uint64_t __x, int __c) { - return __binary_clz4( - __x >> 4*!!(__x & 0xF0), - __c + 4*!(__x & 0xF0)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_clz8(uint64_t __x, int __c) +{ + return __binary_clz4(__x >> 4 * !!(__x & 0xF0), __c + 4 * !(__x & 0xF0)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_clz16(uint64_t __x, int __c) { - return __binary_clz8( - __x >> 8*!!(__x & 0xFF00), - __c + 8*!(__x & 0xFF00)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_clz16(uint64_t __x, int __c) +{ + return __binary_clz8(__x >> 8 * !!(__x & 0xFF00), __c + 8 * !(__x & 0xFF00)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_clz32(uint64_t __x, int __c) { - return __binary_clz16( - __x >> 16*!!(__x & 0xFFFF0000), - __c + 16*!(__x & 0xFFFF0000)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_clz32(uint64_t __x, int __c) +{ + return __binary_clz16(__x >> 16 * !!(__x & 0xFFFF0000), __c + 16 * !(__x & 0xFFFF0000)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __binary_clz64(uint64_t __x) { - return __binary_clz32( - __x >> 32*!!(__x & 0xFFFFFFFF00000000), - 32*!(__x & 0xFFFFFFFF00000000)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __binary_clz64(uint64_t __x) +{ + return __binary_clz32(__x >> 32 * !!(__x & 0xFFFFFFFF00000000), 32 * !(__x & 0xFFFFFFFF00000000)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __fallback_popc8(uint64_t __x) { +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __fallback_popc8(uint64_t __x) +{ return static_cast((__x * 0x0101010101010101) >> 56); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __fallback_popc16(uint64_t __x) { - return __fallback_popc8( - (__x + (__x >> 4)) & 0x0f0f0f0f0f0f0f0f); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __fallback_popc16(uint64_t __x) +{ + return __fallback_popc8((__x + (__x >> 4)) & 0x0f0f0f0f0f0f0f0f); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __fallback_popc32(uint64_t __x) { - return __fallback_popc16( - (__x & 0x3333333333333333) + ((__x >> 2) & 0x3333333333333333)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __fallback_popc32(uint64_t __x) +{ + return __fallback_popc16((__x & 0x3333333333333333) + ((__x >> 2) & 0x3333333333333333)); } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __fallback_popc64(uint64_t __x) { - return __fallback_popc32( - __x - ((__x >> 1) & 0x5555555555555555)); +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __fallback_popc64(uint64_t __x) +{ + return __fallback_popc32(__x - ((__x >> 1) & 0x5555555555555555)); } #ifndef _CCCL_COMPILER_MSVC -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr -int __libcpp_ctz(unsigned __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return (!__x) ? sizeof(unsigned) * 8 : __ffs(__x) - 1; - ), ( - return __builtin_ctz(__x); - )) +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_ctz(unsigned __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET( + NV_IS_DEVICE, (return (!__x) ? sizeof(unsigned) * 8 : __ffs(__x) - 1;), (return __builtin_ctz(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - - return __binary_ctz32(static_cast(__x), 0); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv - return __builtin_ctz(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 -} - -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_ctz(unsigned long __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return (!__x) ? sizeof(unsigned long) * 8 : __ffsll(__x) - 1; - ), ( - return __builtin_ctzl(__x); - )) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + + return __binary_ctz32(static_cast(__x), 0); +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv + return __builtin_ctz(__x); +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +} + +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_ctz(unsigned long __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET( + NV_IS_DEVICE, (return (!__x) ? sizeof(unsigned long) * 8 : __ffsll(__x) - 1;), (return __builtin_ctzl(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - return __binary_ctz64(static_cast(__x)); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv - return __builtin_ctzl(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 + return __binary_ctz64(static_cast(__x)); +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv + return __builtin_ctzl(__x); +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 } -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_ctz(unsigned long long __x) noexcept { +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_ctz(unsigned long long __x) noexcept +{ // For whatever reason __builtin_ctzll does not compile although it should -#if 1 //def _CCCL_COMPILER_NVRTC -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return (!__x) ? sizeof(unsigned long long) * 8 : __ffsll(__x) - 1; - ), ( - return __builtin_ctzll(__x); - )) +# if 1 // def _CCCL_COMPILER_NVRTC +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, + (return (!__x) ? sizeof(unsigned long long) * 8 : __ffsll(__x) - 1;), + (return __builtin_ctzll(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - - return __binary_ctz64(static_cast(__x)); -#else // 0 - return __builtin_ctzll(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 -} - -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_clz(unsigned __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return __clz(__x); - ), ( - return __builtin_clz(__x); - )) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + + return __binary_ctz64(static_cast(__x)); +# else // 0 + return __builtin_ctzll(__x); +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +} + +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_clz(unsigned __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return __clz(__x);), (return __builtin_clz(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) return __binary_clz32(static_cast(__x), 0); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv return __builtin_clz(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 -} - -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_clz(unsigned long __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return __clzll(__x); - ), ( - return __builtin_clzl(__x); - )) +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +} + +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_clz(unsigned long __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return __clzll(__x);), (return __builtin_clzl(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) return __binary_clz64(static_cast(__x)); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv return __builtin_clzl(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 -} - -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_clz(unsigned long long __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return __clzll(__x); - ), ( - return __builtin_clzll(__x); - )) +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +} + +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_clz(unsigned long long __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return __clzll(__x);), (return __builtin_clzll(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) return __binary_clz64(static_cast(__x)); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv return __builtin_clzll(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 -} - -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_popcount(unsigned __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return __popc(__x); - ), ( - return __builtin_popcount(__x); - )) +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +} + +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_popcount(unsigned __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return __popc(__x);), (return __builtin_popcount(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) return __fallback_popc64(static_cast(__x)); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv return __builtin_popcount(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 -} - -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_popcount(unsigned long __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return __popcll(__x); - ), ( - return __builtin_popcountl(__x); - )) +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +} + +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_popcount(unsigned long __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return __popcll(__x);), (return __builtin_popcountl(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) return __fallback_popc64(static_cast(__x)); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv return __builtin_popcountl(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 -} - -inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __libcpp_popcount(unsigned long long __x) noexcept { -#if defined(_CCCL_COMPILER_NVRTC) \ - || (defined(_CCCL_CUDACC_BELOW_11_3)) -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) - if (!__libcpp_is_constant_evaluated()) { - NV_IF_ELSE_TARGET(NV_IS_DEVICE, ( - return __popcll(__x); - ), ( - return __builtin_popcountll(__x); - )) +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +} + +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __libcpp_popcount(unsigned long long __x) noexcept +{ +# if defined(_CCCL_COMPILER_NVRTC) || (defined(_CCCL_CUDACC_BELOW_11_3)) +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) + if (!__libcpp_is_constant_evaluated()) + { + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return __popcll(__x);), (return __builtin_popcountll(__x);)) } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && (_CCCL_STD_VER >= 2014) return __fallback_popc64(static_cast(__x)); -#else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv +# else // ^^^ _CCCL_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 vvv return __builtin_popcountll(__x); -#endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 +# endif // !_CCCL_COMPILER_NVRTC || nvcc >= 11.3 } -#else // _CCCL_COMPILER_MSVC +#else // _CCCL_COMPILER_MSVC // Precondition: __x != 0 -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_ctz(unsigned __x) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_ctz(unsigned __x) +{ static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); static_assert(sizeof(unsigned long) == 4, ""); -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) - if (!__libcpp_is_constant_evaluated()) { +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) + if (!__libcpp_is_constant_evaluated()) + { unsigned long __where = 0; if (_BitScanForward(&__where, __x)) + { return static_cast(__where); + } return 32; } -#endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) +# endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) return __binary_ctz32(static_cast(__x), 0); } -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_ctz(unsigned long __x) { - static_assert(sizeof(unsigned long) == sizeof(unsigned), ""); - return __libcpp_ctz(static_cast(__x)); +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_ctz(unsigned long __x) +{ + static_assert(sizeof(unsigned long) == sizeof(unsigned), ""); + return __libcpp_ctz(static_cast(__x)); } -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_ctz(unsigned long long __x) { -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) - if (!__libcpp_is_constant_evaluated()) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_ctz(unsigned long long __x) +{ +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) + if (!__libcpp_is_constant_evaluated()) + { unsigned long __where = 0; -# if defined(_LIBCUDACXX_HAS_BITSCAN64) && (defined(_M_AMD64) || defined(__x86_64__)) +# if defined(_LIBCUDACXX_HAS_BITSCAN64) && (defined(_M_AMD64) || defined(__x86_64__)) if (_BitScanForward64(&__where, __x)) + { return static_cast(__where); -# else + } +# else // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. if (_BitScanForward(&__where, static_cast(__x))) + { return static_cast(__where); + } if (_BitScanForward(&__where, static_cast(__x >> 32))) + { return static_cast(__where + 32); -# endif + } +# endif return 64; } -#endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) +# endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) return __binary_ctz64(__x); } // Precondition: __x != 0 -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_clz(unsigned __x) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_clz(unsigned __x) +{ static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); static_assert(sizeof(unsigned long) == 4, ""); -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) - if (!__libcpp_is_constant_evaluated()) { +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) + if (!__libcpp_is_constant_evaluated()) + { unsigned long __where = 0; if (_BitScanReverse(&__where, __x)) + { return static_cast(31 - __where); + } return 32; // Undefined Behavior. } -#endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) +# endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) return __binary_clz32(static_cast(__x), 0); } -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_clz(unsigned long __x) { - static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); - return __libcpp_clz(static_cast(__x)); +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_clz(unsigned long __x) +{ + static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); + return __libcpp_clz(static_cast(__x)); } -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_clz(unsigned long long __x) { -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) - if (!__libcpp_is_constant_evaluated()) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_clz(unsigned long long __x) +{ +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) + if (!__libcpp_is_constant_evaluated()) + { unsigned long __where = 0; -# if defined(_LIBCUDACXX_HAS_BITSCAN64) +# if defined(_LIBCUDACXX_HAS_BITSCAN64) if (_BitScanReverse64(&__where, __x)) + { return static_cast(63 - __where); -# else + } +# else // Win32 doesn't have _BitScanReverse64 so emulate it with two 32 bit calls. if (_BitScanReverse(&__where, static_cast(__x >> 32))) + { return static_cast(63 - (__where + 32)); + } if (_BitScanReverse(&__where, static_cast(__x))) + { return static_cast(63 - __where); -# endif + } +# endif return 64; // Undefined Behavior. } -#endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) +# endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) return __binary_clz64(static_cast(__x)); } -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_popcount(unsigned __x) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_popcount(unsigned __x) +{ static_assert(sizeof(unsigned) == 4, ""); -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) - if (!__libcpp_is_constant_evaluated()) { +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) + if (!__libcpp_is_constant_evaluated()) + { return static_cast(__popcnt(__x)); } -#endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) +# endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) return __fallback_popc64(static_cast(__x)); } -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_popcount(unsigned long __x) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_popcount(unsigned long __x) +{ static_assert(sizeof(unsigned long) == 4, ""); -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) - if (!__libcpp_is_constant_evaluated()) { +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) + if (!__libcpp_is_constant_evaluated()) + { return static_cast(__popcnt(__x)); } -#endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) +# endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__) return __fallback_popc64(static_cast(__x)); } -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr int __libcpp_popcount(unsigned long long __x) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr int __libcpp_popcount(unsigned long long __x) +{ static_assert(sizeof(unsigned long long) == 8, ""); -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) - if (!__libcpp_is_constant_evaluated()) { +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(__CUDA_ARCH__) + if (!__libcpp_is_constant_evaluated()) + { return static_cast(__popcnt64(__x)); } -#endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__ +# endif // _LIBCUDACXX_IS_CONSTANT_EVALUATED && !defined(__CUDA_ARCH__ return __fallback_popc64(static_cast(__x)); } #endif // _CCCL_COMPILER_MSVC -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -_Tp __rotl(_Tp __t, unsigned int __cnt) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR _Tp __rotl(_Tp __t, unsigned int __cnt) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires unsigned"); - using __nlt = numeric_limits<_Tp>; + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires unsigned"); + using __nlt = numeric_limits<_Tp>; - return ((__cnt % __nlt::digits) == 0) ? - __t : - (__t << (__cnt % __nlt::digits)) | (__t >> (__nlt::digits - (__cnt % __nlt::digits))); + return ((__cnt % __nlt::digits) == 0) + ? __t + : (__t << (__cnt % __nlt::digits)) | (__t >> (__nlt::digits - (__cnt % __nlt::digits))); } - -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -_Tp __rotr(_Tp __t, unsigned int __cnt) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR _Tp __rotr(_Tp __t, unsigned int __cnt) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires unsigned"); - using __nlt = numeric_limits<_Tp>; + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires unsigned"); + using __nlt = numeric_limits<_Tp>; - return ((__cnt % __nlt::digits) == 0) ? - __t : - (__t >> (__cnt % __nlt::digits)) | (__t << (__nlt::digits - (__cnt % __nlt::digits))); + return ((__cnt % __nlt::digits) == 0) + ? __t + : (__t >> (__cnt % __nlt::digits)) | (__t << (__nlt::digits - (__cnt % __nlt::digits))); } // Forward decl for recursive use in split word operations -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __countr_zero(_Tp __t) noexcept; +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __countr_zero(_Tp __t) noexcept; -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t __countr_zero_dispatch(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t +__countr_zero_dispatch(_Tp __t) noexcept { return __libcpp_ctz(static_cast(__t)); } -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t __countr_zero_dispatch(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t +__countr_zero_dispatch(_Tp __t) noexcept { return __libcpp_ctz(static_cast(__t)); } -template -struct __countr_zero_rsh_impl { - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __short_circuit(_Tp __t, int __cur, int __count) { - // Stops processing early if non-zero - return (__cur == numeric_limits::digits) ? - __countr_zero_rsh_impl<_Tp, _St-1>::__count(__t, __cur + __count) : - __cur + __count; - } +template +struct __countr_zero_rsh_impl +{ + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __short_circuit(_Tp __t, int __cur, int __count) + { + // Stops processing early if non-zero + return (__cur == numeric_limits::digits) + ? __countr_zero_rsh_impl<_Tp, _St - 1>::__count(__t, __cur + __count) + : __cur + __count; + } - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __count(_Tp __t, int __count) { - return __short_circuit( - __t >> numeric_limits::digits, - __countr_zero(static_cast(__t)), - __count); - } + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __count(_Tp __t, int __count) + { + return __short_circuit( + __t >> numeric_limits::digits, __countr_zero(static_cast(__t)), __count); + } }; template -struct __countr_zero_rsh_impl<_Tp, 1> { - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __count(_Tp __t, int __count) { - return __count + __countr_zero(static_cast(__t)); - } +struct __countr_zero_rsh_impl<_Tp, 1> +{ + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __count(_Tp __t, int __count) + { + return __count + __countr_zero(static_cast(__t)); + } }; -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<(sizeof(_Tp) > sizeof(unsigned long long)), int> __countr_zero_dispatch(_Tp __t) noexcept -{ return __countr_zero_rsh_impl<_Tp>::__count(__t, 0); } +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<(sizeof(_Tp) > sizeof(unsigned long long)), int> +__countr_zero_dispatch(_Tp __t) noexcept +{ + return __countr_zero_rsh_impl<_Tp>::__count(__t, 0); +} -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __countr_zero(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __countr_zero(_Tp __t) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_zero requires unsigned"); + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_zero requires unsigned"); - return __t ? __countr_zero_dispatch(__t) : numeric_limits<_Tp>::digits; + return __t ? __countr_zero_dispatch(__t) : numeric_limits<_Tp>::digits; } // Forward decl for recursive use in split word operations -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __countl_zero(_Tp __t) noexcept; +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __countl_zero(_Tp __t) noexcept; -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t __countl_zero_dispatch(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t +__countl_zero_dispatch(_Tp __t) noexcept { return __libcpp_clz(static_cast(__t)) - - (numeric_limits::digits - numeric_limits<_Tp>::digits); + - (numeric_limits::digits - numeric_limits<_Tp>::digits); } -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t __countl_zero_dispatch(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t +__countl_zero_dispatch(_Tp __t) noexcept { return __libcpp_clz(static_cast(__t)) - - (numeric_limits::digits - numeric_limits<_Tp>::digits); + - (numeric_limits::digits - numeric_limits<_Tp>::digits); } -template -struct __countl_zero_rotl_impl { - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __short_circuit(_Tp __t, int __cur) { - // This stops processing early if the current word is not empty - return (__cur == numeric_limits::digits) ? - __cur + __countl_zero_rotl_impl<_Tp, _St-1>::__count(__t) : - __cur; - } +template +struct __countl_zero_rotl_impl +{ + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __short_circuit(_Tp __t, int __cur) + { + // This stops processing early if the current word is not empty + return (__cur == numeric_limits::digits) + ? __cur + __countl_zero_rotl_impl<_Tp, _St - 1>::__count(__t) + : __cur; + } - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __countl_iter(_Tp __t) { - // After rotating pass result of clz to another step for processing - return __short_circuit( - __t, - __countl_zero(static_cast(__t))); - } + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __countl_iter(_Tp __t) + { + // After rotating pass result of clz to another step for processing + return __short_circuit(__t, __countl_zero(static_cast(__t))); + } - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __count(_Tp __t) { - return __countl_iter( - __rotl(__t, numeric_limits::digits)); - } + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __count(_Tp __t) + { + return __countl_iter(__rotl(__t, numeric_limits::digits)); + } }; template -struct __countl_zero_rotl_impl<_Tp, 1> { - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __count(_Tp __t) { - return __countl_zero(static_cast(__rotl(__t, numeric_limits::digits))); - } +struct __countl_zero_rotl_impl<_Tp, 1> +{ + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __count(_Tp __t) + { + return __countl_zero(static_cast(__rotl(__t, numeric_limits::digits))); + } }; -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<(sizeof(_Tp) > sizeof(unsigned long long)), int> __countl_zero_dispatch(_Tp __t) noexcept -{ return __countl_zero_rotl_impl<_Tp>::__count(__t); } - -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __countl_zero(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<(sizeof(_Tp) > sizeof(unsigned long long)), int> +__countl_zero_dispatch(_Tp __t) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires unsigned"); - return __t ? __countl_zero_dispatch(__t) : numeric_limits<_Tp>::digits; + return __countl_zero_rotl_impl<_Tp>::__count(__t); } -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __countl_one(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __countl_zero(_Tp __t) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_one requires unsigned"); - return __t != numeric_limits<_Tp>::max() - ? __countl_zero(static_cast<_Tp>(~__t)) - : numeric_limits<_Tp>::digits; + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_zero requires unsigned"); + return __t ? __countl_zero_dispatch(__t) : numeric_limits<_Tp>::digits; } +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __countl_one(_Tp __t) noexcept +{ + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countl_one requires unsigned"); + return __t != numeric_limits<_Tp>::max() ? __countl_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits; +} -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __countr_one(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __countr_one(_Tp __t) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_one requires unsigned"); - return __t != numeric_limits<_Tp>::max() - ? __countr_zero(static_cast<_Tp>(~__t)) - : numeric_limits<_Tp>::digits; + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__countr_one requires unsigned"); + return __t != numeric_limits<_Tp>::max() ? __countr_zero(static_cast<_Tp>(~__t)) : numeric_limits<_Tp>::digits; } -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t __popcount_dispatch(_Tp __t) noexcept -{ return __libcpp_popcount(static_cast(__t)); } +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t +__popcount_dispatch(_Tp __t) noexcept +{ + return __libcpp_popcount(static_cast(__t)); +} -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t __popcount_dispatch(_Tp __t) noexcept -{ return __libcpp_popcount(static_cast(__t)); } +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t +__popcount_dispatch(_Tp __t) noexcept +{ + return __libcpp_popcount(static_cast(__t)); +} -template -struct __popcount_rsh_impl { - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __count(_Tp __t) { - return __popcount_rsh_impl<_Tp, _St-1>::__count( - __t >> numeric_limits::digits) + - __libcpp_popcount(static_cast(__t)); - } +template +struct __popcount_rsh_impl +{ + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __count(_Tp __t) + { + return __popcount_rsh_impl<_Tp, _St - 1>::__count(__t >> numeric_limits::digits) + + __libcpp_popcount(static_cast(__t)); + } }; template -struct __popcount_rsh_impl<_Tp, 1> { - static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR - int __count(_Tp __t) { - return __libcpp_popcount(static_cast(__t)); - } +struct __popcount_rsh_impl<_Tp, 1> +{ + static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __count(_Tp __t) + { + return __libcpp_popcount(static_cast(__t)); + } }; -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<(sizeof(_Tp) > sizeof(unsigned long long)), int> __popcount_dispatch(_Tp __t) noexcept -{ return __popcount_rsh_impl<_Tp>::__count(__t); } +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<(sizeof(_Tp) > sizeof(unsigned long long)), int> +__popcount_dispatch(_Tp __t) noexcept +{ + return __popcount_rsh_impl<_Tp>::__count(__t); +} -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -int __popcount(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR int __popcount(_Tp __t) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__libcpp_popcount requires unsigned"); + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__libcpp_popcount requires unsigned"); - return __popcount_dispatch(__t); + return __popcount_dispatch(__t); } - // integral log base 2 -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -unsigned __bit_log2(_Tp __t) noexcept +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR unsigned __bit_log2(_Tp __t) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__bit_log2 requires unsigned"); - return std::numeric_limits<_Tp>::digits - 1 - __countl_zero(__t); + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__bit_log2 requires unsigned"); + return std::numeric_limits<_Tp>::digits - 1 - __countl_zero(__t); } template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -bool __has_single_bit(_Tp __t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR bool __has_single_bit(_Tp __t) noexcept { - static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__has_single_bit requires unsigned"); - return __t != 0 && (((__t & (__t - 1)) == 0)); + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__has_single_bit requires unsigned"); + return __t != 0 && (((__t & (__t - 1)) == 0)); } template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t= sizeof(unsigned), _Tp> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t= sizeof(unsigned), _Tp> __ceil2(_Tp __t) noexcept { - // const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u)); - // _LIBCUDACXX_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to ceil2"); - return _Tp{1} << (numeric_limits<_Tp>::digits - __countl_zero((_Tp)(__t - 1u))); + // const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u)); + // _LIBCUDACXX_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to + // ceil2"); + return _Tp{1} << (numeric_limits<_Tp>::digits - __countl_zero((_Tp) (__t - 1u))); } template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t __ceil2(_Tp __t) noexcept { - // const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u)); - // _LIBCUDACXX_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to ceil2"); + // const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u)); + // _LIBCUDACXX_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to + // ceil2"); - // const unsigned __extra = numeric_limits::digits - numeric_limits<_Tp>::digits; - // const unsigned __retVal = 1u << (__n + __extra); - return (_Tp) - ((1u << ((numeric_limits<_Tp>::digits - __countl_zero((_Tp)(__t - 1u))) + (numeric_limits::digits - numeric_limits<_Tp>::digits))) >> - (numeric_limits::digits - numeric_limits<_Tp>::digits)); + // const unsigned __extra = numeric_limits::digits - numeric_limits<_Tp>::digits; + // const unsigned __retVal = 1u << (__n + __extra); + return (_Tp) ((1u << ((numeric_limits<_Tp>::digits - __countl_zero((_Tp) (__t - 1u))) + + (numeric_limits::digits - numeric_limits<_Tp>::digits))) + >> (numeric_limits::digits - numeric_limits<_Tp>::digits)); } - #if (_CCCL_STD_VER > 2017) || defined(__cuda_std__) -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> rotl(_Tp __t, unsigned int __cnt) noexcept { - return __rotl(__t, __cnt); + return __rotl(__t, __cnt); } - // rotr -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> rotr(_Tp __t, unsigned int __cnt) noexcept { - return __rotr(__t, __cnt); + return __rotr(__t, __cnt); } - -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> countl_zero(_Tp __t) noexcept { - return __countl_zero(__t); + return __countl_zero(__t); } - -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> countl_one(_Tp __t) noexcept { - return __countl_one(__t); + return __countl_one(__t); } - -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> countr_zero(_Tp __t) noexcept { - return __countr_zero(__t); + return __countr_zero(__t); } - -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> countr_one(_Tp __t) noexcept { - return __countr_one(__t); + return __countr_one(__t); } - -template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> +template +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, int> popcount(_Tp __t) noexcept { - return __popcount(__t); + return __popcount(__t); } - template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, bool> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, bool> has_single_bit(_Tp __t) noexcept { - return __has_single_bit(__t); + return __has_single_bit(__t); } template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> bit_floor(_Tp __t) noexcept { - return __t == 0 ? 0 : static_cast<_Tp>(_Tp{1} << __bit_log2(__t)); + return __t == 0 ? 0 : static_cast<_Tp>(_Tp{1} << __bit_log2(__t)); } template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> bit_ceil(_Tp __t) noexcept { - return (__t < 2) ? 1 : static_cast<_Tp>(__ceil2(__t)); + return (__t < 2) ? 1 : static_cast<_Tp>(__ceil2(__t)); } template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR -__enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_BIT_CONSTEXPR __enable_if_t<__libcpp_is_unsigned_integer<_Tp>::value, _Tp> bit_width(_Tp __t) noexcept { - return __t == 0 ? 0 : static_cast<_Tp>(__bit_log2(__t) + 1); + return __t == 0 ? 0 : static_cast<_Tp>(__bit_log2(__t) + 1); } - enum class endian { - little = 0xDEAD, - big = 0xFACE, -#if defined(_LIBCUDACXX_LITTLE_ENDIAN) - native = little -#elif defined(_LIBCUDACXX_BIG_ENDIAN) - native = big -#else - native = 0xCAFE -#endif + little = 0xDEAD, + big = 0xFACE, +# if defined(_LIBCUDACXX_LITTLE_ENDIAN) + native = little +# elif defined(_LIBCUDACXX_BIG_ENDIAN) + native = big +# else + native = 0xCAFE +# endif }; #endif // _CCCL_STD_VER > 2017 diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cassert b/libcudacxx/include/cuda/std/detail/libcxx/include/cassert index f995ee8e79b..0a66560dc38 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cassert +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cassert @@ -20,8 +20,9 @@ Macros: #define _LIBCUDACXX_CASSERT #ifndef _CCCL_COMPILER_NVRTC -#include -#include +# include + +# include #endif //_CCCL_COMPILER_NVRTC -#endif // _LIBCUDACXX_CASSERT +#endif // _LIBCUDACXX_CASSERT diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/ccomplex b/libcudacxx/include/cuda/std/detail/libcxx/include/ccomplex index fca1dcf1edb..487b6d5e7a9 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/ccomplex +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/ccomplex @@ -19,14 +19,4 @@ #include -#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 - -// hh 080623 Created - -#endif // _LIBCUDACXX_CCOMPLEX +#endif // _LIBCUDACXX_CCOMPLEX diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cfloat b/libcudacxx/include/cuda/std/detail/libcxx/include/cfloat index 142e40313e3..9480e45cdf6 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cfloat +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cfloat @@ -70,8 +70,9 @@ Macros: */ #ifndef _CCCL_COMPILER_NVRTC -#include -#include +# include + +# include #endif // _CCCL_COMPILER_NVRTC -#endif // _LIBCUDACXX_CFLOAT +#endif // _LIBCUDACXX_CFLOAT diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/chrono b/libcudacxx/include/cuda/std/detail/libcxx/include/chrono index 43b22135e6d..1f2b5e48921 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/chrono +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/chrono @@ -834,18 +834,18 @@ constexpr chrono::year operator ""y(unsigned lo #endif // no system header #ifdef __cuda_std__ -#ifndef _CCCL_COMPILER_NVRTC -#include -#endif // _CCCL_COMPILER_NVRTC +# ifndef _CCCL_COMPILER_NVRTC +# include +# endif // _CCCL_COMPILER_NVRTC #endif // __cuda_std__ -#include // all public C++ headers provide the assertion handler #include #include #include #include #include #include +#include // all public C++ headers provide the assertion handler #include #include @@ -869,181 +869,179 @@ _LIBCUDACXX_BEGIN_NAMESPACE_FILESYSTEM struct _FilesystemClock; _LIBCUDACXX_END_NAMESPACE_FILESYSTEM -# if _LIBCUDACXX_CUDA_ABI_VERSION > 3 +#if _LIBCUDACXX_CUDA_ABI_VERSION > 3 # define _LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T double -# else +#else # define _LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T long double -# endif +#endif _LIBCUDACXX_BEGIN_NAMESPACE_STD namespace chrono { -template > class _LIBCUDACXX_TEMPLATE_VIS duration; +template > +class _LIBCUDACXX_TEMPLATE_VIS duration; template -struct __is_duration : false_type {}; +struct __is_duration : false_type +{}; template -struct __is_duration > : true_type {}; +struct __is_duration> : true_type +{}; template -struct __is_duration > : true_type {}; +struct __is_duration> : true_type +{}; template -struct __is_duration > : true_type {}; +struct __is_duration> : true_type +{}; template -struct __is_duration > : true_type {}; +struct __is_duration> : true_type +{}; -} // chrono +} // namespace chrono template -struct _LIBCUDACXX_TEMPLATE_VIS common_type, - chrono::duration<_Rep2, _Period2> > +struct _LIBCUDACXX_TEMPLATE_VIS common_type, chrono::duration<_Rep2, _Period2>> { - typedef chrono::duration::type, - typename __ratio_gcd<_Period1, _Period2>::type> type; + typedef chrono::duration::type, typename __ratio_gcd<_Period1, _Period2>::type> + type; }; -namespace chrono { +namespace chrono +{ // duration_cast -template ::type, - bool = _Period::num == 1, - bool = _Period::den == 1> + bool = _Period::num == 1, + bool = _Period::den == 1> struct __duration_cast; template struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _ToDuration operator()(const _FromDuration& __fd) const - { - return _ToDuration(static_cast(__fd.count())); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr _ToDuration operator()(const _FromDuration& __fd) const + { + return _ToDuration(static_cast(__fd.count())); + } }; template struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _ToDuration operator()(const _FromDuration& __fd) const - { - typedef typename common_type::type _Ct; - return _ToDuration(static_cast( - static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type::type _Ct; + return _ToDuration( + static_cast(static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); + } }; template struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _ToDuration operator()(const _FromDuration& __fd) const - { - typedef typename common_type::type _Ct; - return _ToDuration(static_cast( - static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type::type _Ct; + return _ToDuration( + static_cast(static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); + } }; template struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _ToDuration operator()(const _FromDuration& __fd) const - { - typedef typename common_type::type _Ct; - return _ToDuration(static_cast( - static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) - / static_cast<_Ct>(_Period::den))); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr _ToDuration operator()(const _FromDuration& __fd) const + { + typedef typename common_type::type _Ct; + return _ToDuration(static_cast( + static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) / static_cast<_Ct>(_Period::den))); + } }; template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -__enable_if_t -< - __is_duration<_ToDuration>::value, - _ToDuration -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t<__is_duration<_ToDuration>::value, _ToDuration> duration_cast(const duration<_Rep, _Period>& __fd) { - return __duration_cast, _ToDuration>()(__fd); + return __duration_cast, _ToDuration>()(__fd); } template -struct _LIBCUDACXX_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; +struct _LIBCUDACXX_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> +{}; #if _CCCL_STD_VER > 2011 && !defined(_LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES) template -_LIBCUDACXX_INLINE_VAR constexpr bool treat_as_floating_point_v - = treat_as_floating_point<_Rep>::value; +_LIBCUDACXX_INLINE_VAR constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>::value; #endif // _CCCL_STD_VER > 2011 && !defined(_LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES) template struct _LIBCUDACXX_TEMPLATE_VIS duration_values { public: - _LIBCUDACXX_INLINE_VISIBILITY static constexpr _Rep zero() noexcept {return _Rep(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr _Rep max() noexcept {return numeric_limits<_Rep>::max();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr _Rep min() noexcept {return numeric_limits<_Rep>::lowest();} + _LIBCUDACXX_INLINE_VISIBILITY static constexpr _Rep zero() noexcept + { + return _Rep(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr _Rep max() noexcept + { + return numeric_limits<_Rep>::max(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr _Rep min() noexcept + { + return numeric_limits<_Rep>::lowest(); + } }; #if _CCCL_STD_VER > 2011 template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -__enable_if_t -< - __is_duration<_ToDuration>::value, - _ToDuration -> +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __enable_if_t<__is_duration<_ToDuration>::value, _ToDuration> floor(const duration<_Rep, _Period>& __d) { - _ToDuration __t = duration_cast<_ToDuration>(__d); - if (__t > __d) - __t = __t - _ToDuration{1}; - return __t; + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t > __d) + { + __t = __t - _ToDuration{1}; + } + return __t; } template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -__enable_if_t -< - __is_duration<_ToDuration>::value, - _ToDuration -> +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __enable_if_t<__is_duration<_ToDuration>::value, _ToDuration> ceil(const duration<_Rep, _Period>& __d) { - _ToDuration __t = duration_cast<_ToDuration>(__d); - if (__t < __d) - __t = __t + _ToDuration{1}; - return __t; + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t < __d) + { + __t = __t + _ToDuration{1}; + } + return __t; } template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -__enable_if_t -< - __is_duration<_ToDuration>::value, - _ToDuration -> +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __enable_if_t<__is_duration<_ToDuration>::value, _ToDuration> round(const duration<_Rep, _Period>& __d) { - _ToDuration __lower = floor<_ToDuration>(__d); - _ToDuration __upper = __lower + _ToDuration{1}; - auto __lowerDiff = __d - __lower; - auto __upperDiff = __upper - __d; - if (__lowerDiff < __upperDiff) - return __lower; - if (__lowerDiff > __upperDiff) - return __upper; - return __lower.count() & 1 ? __upper : __lower; + _ToDuration __lower = floor<_ToDuration>(__d); + _ToDuration __upper = __lower + _ToDuration{1}; + auto __lowerDiff = __d - __lower; + auto __upperDiff = __upper - __d; + if (__lowerDiff < __upperDiff) + { + return __lower; + } + if (__lowerDiff > __upperDiff) + { + return __upper; + } + return __lower.count() & 1 ? __upper : __lower; } #endif // _CCCL_STD_VER > 2011 @@ -1052,150 +1050,199 @@ round(const duration<_Rep, _Period>& __d) template class _LIBCUDACXX_TEMPLATE_VIS duration { - static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); - static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); - static_assert(_Period::num > 0, "duration period must be positive"); + static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); + static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); + static_assert(_Period::num > 0, "duration period must be positive"); - template - struct __no_overflow + template + struct __no_overflow + { + private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + static const intmax_t __n1 = _R1::num / __gcd_n1_n2; + static const intmax_t __d1 = _R1::den / __gcd_d1_d2; + static const intmax_t __n2 = _R2::num / __gcd_n1_n2; + static const intmax_t __d2 = _R2::den / __gcd_d1_d2; + static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); + + template + struct __mul // __overflow == false { - private: - static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; - static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; - static const intmax_t __n1 = _R1::num / __gcd_n1_n2; - static const intmax_t __d1 = _R1::den / __gcd_d1_d2; - static const intmax_t __n2 = _R2::num / __gcd_n1_n2; - static const intmax_t __d2 = _R2::den / __gcd_d1_d2; - static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); - - template - struct __mul // __overflow == false - { - static const intmax_t value = _Xp * _Yp; - }; - - template - struct __mul<_Xp, _Yp, true> - { - static const intmax_t value = 1; - }; - - public: - static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); - typedef ratio<__mul<__n1, __d2, !value>::value, - __mul<__n2, __d1, !value>::value> type; + static const intmax_t value = _Xp * _Yp; }; -public: - typedef _Rep rep; - typedef typename _Period::type period; -private: - rep __rep_; -public: - - constexpr duration() = default; + template + struct __mul<_Xp, _Yp, true> + { + static const intmax_t value = 1; + }; - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit duration(const _Rep2& __r, - __enable_if_t - < - is_convertible<_Rep2, rep>::value && - (treat_as_floating_point::value || - !treat_as_floating_point<_Rep2>::value) - >* = 0) - : __rep_(static_cast(__r)) {} + public: + static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); + typedef ratio<__mul<__n1, __d2, !value>::value, __mul<__n2, __d1, !value>::value> type; + }; - // conversions - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - duration(const duration<_Rep2, _Period2>& __d, - __enable_if_t - < - __no_overflow<_Period2, period>::value && ( - treat_as_floating_point::value || - (__no_overflow<_Period2, period>::type::den == 1 && - !treat_as_floating_point<_Rep2>::value)) - >* = 0) - : __rep_(_CUDA_VSTD::chrono::duration_cast(__d).count()) {} +public: + typedef _Rep rep; + typedef typename _Period::type period; - // observer +private: + rep __rep_; - _LIBCUDACXX_INLINE_VISIBILITY constexpr rep count() const {return __rep_;} +public: + constexpr duration() = default; + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit duration( + const _Rep2& __r, + __enable_if_t::value + && (treat_as_floating_point::value || !treat_as_floating_point<_Rep2>::value)>* = 0) + : __rep_(static_cast(__r)) + {} + + // conversions + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr duration( + const duration<_Rep2, _Period2>& __d, + __enable_if_t<__no_overflow<_Period2, period>::value + && (treat_as_floating_point::value + || (__no_overflow<_Period2, period>::type::den == 1 && !treat_as_floating_point<_Rep2>::value))>* = + 0) + : __rep_(_CUDA_VSTD::chrono::duration_cast(__d).count()) + {} + + // observer + + _LIBCUDACXX_INLINE_VISIBILITY constexpr rep count() const + { + return __rep_; + } - // arithmetic + // arithmetic - _LIBCUDACXX_INLINE_VISIBILITY constexpr typename common_type::type operator+() const {return typename common_type::type(*this);} - _LIBCUDACXX_INLINE_VISIBILITY constexpr typename common_type::type operator-() const {return typename common_type::type(-__rep_);} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator++() {++__rep_; return *this;} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration operator++(int) {return duration(__rep_++);} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator--() {--__rep_; return *this;} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration operator--(int) {return duration(__rep_--);} + _LIBCUDACXX_INLINE_VISIBILITY constexpr typename common_type::type operator+() const + { + return typename common_type::type(*this); + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr typename common_type::type operator-() const + { + return typename common_type::type(-__rep_); + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator++() + { + ++__rep_; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration operator++(int) + { + return duration(__rep_++); + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator--() + { + --__rep_; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration operator--(int) + { + return duration(__rep_--); + } - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator+=(const duration& __d) + { + __rep_ += __d.count(); + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator-=(const duration& __d) + { + __rep_ -= __d.count(); + return *this; + } - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator*=(const rep& rhs) + { + __rep_ *= rhs; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator/=(const rep& rhs) + { + __rep_ /= rhs; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator%=(const rep& rhs) + { + __rep_ %= rhs; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 duration& operator%=(const duration& rhs) + { + __rep_ %= rhs.count(); + return *this; + } - // special values + // special values - _LIBCUDACXX_INLINE_VISIBILITY static constexpr duration zero() noexcept {return duration(duration_values::zero());} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr duration min() noexcept {return duration(duration_values::min());} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr duration max() noexcept {return duration(duration_values::max());} + _LIBCUDACXX_INLINE_VISIBILITY static constexpr duration zero() noexcept + { + return duration(duration_values::zero()); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr duration min() noexcept + { + return duration(duration_values::min()); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr duration max() noexcept + { + return duration(duration_values::max()); + } }; -typedef duration nanoseconds; -typedef duration microseconds; -typedef duration milliseconds; -typedef duration seconds; -typedef duration< long, ratio< 60> > minutes; -typedef duration< long, ratio<3600> > hours; +typedef duration nanoseconds; +typedef duration microseconds; +typedef duration milliseconds; +typedef duration seconds; +typedef duration> minutes; +typedef duration> hours; #if _CCCL_STD_VER > 2011 -typedef duration< int, ratio_multiply, hours::period>> days; -typedef duration< int, ratio_multiply, days::period>> weeks; -typedef duration< int, ratio_multiply, days::period>> years; -typedef duration< int, ratio_divide>> months; +typedef duration, hours::period>> days; +typedef duration, days::period>> weeks; +typedef duration, days::period>> years; +typedef duration>> months; #endif // _CCCL_STD_VER > 2011 // Duration == template struct __duration_eq { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const - { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() == _Ct(__rhs).count(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const + { + typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; + return _Ct(__lhs).count() == _Ct(__rhs).count(); + } }; template struct __duration_eq<_LhsDuration, _LhsDuration> { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const - {return __lhs.count() == __rhs.count();} + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const + { + return __lhs.count() == __rhs.count(); + } }; template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr bool +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_eq, duration<_Rep2, _Period2> >()(__lhs, __rhs); + return __duration_eq, duration<_Rep2, _Period2>>()(__lhs, __rhs); } // Duration != template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr bool +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__lhs == __rhs); + return !(__lhs == __rhs); } // Duration < @@ -1203,169 +1250,142 @@ operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period template struct __duration_lt { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const - { - typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; - return _Ct(__lhs).count() < _Ct(__rhs).count(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const + { + typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; + return _Ct(__lhs).count() < _Ct(__rhs).count(); + } }; template struct __duration_lt<_LhsDuration, _LhsDuration> { - _LIBCUDACXX_INLINE_VISIBILITY constexpr - bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const - {return __lhs.count() < __rhs.count();} + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const + { + return __lhs.count() < __rhs.count(); + } }; template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr bool -operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr bool +operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __duration_lt, duration<_Rep2, _Period2> >()(__lhs, __rhs); + return __duration_lt, duration<_Rep2, _Period2>>()(__lhs, __rhs); } // Duration > template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr bool -operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr bool +operator>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return __rhs < __lhs; + return __rhs < __lhs; } // Duration <= template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr bool +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__rhs < __lhs); + return !(__rhs < __lhs); } // Duration >= template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr bool +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - return !(__lhs < __rhs); + return !(__lhs < __rhs); } // Duration + template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -typename common_type, duration<_Rep2, _Period2> >::type -operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr + typename common_type, duration<_Rep2, _Period2>>::type + operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); + typedef typename common_type, duration<_Rep2, _Period2>>::type _Cd; + return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); } // Duration - template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -typename common_type, duration<_Rep2, _Period2> >::type -operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr + typename common_type, duration<_Rep2, _Period2>>::type + operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); + typedef typename common_type, duration<_Rep2, _Period2>>::type _Cd; + return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); } // Duration * template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -__enable_if_t -< - is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, - duration::type, _Period> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration::type, _Period>> operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -__enable_if_t -< - is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, - duration::type, _Period> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, + duration::type, _Period>> operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) { - return __d * __s; + return __d * __s; } // Duration / template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -__enable_if_t -< - !__is_duration<_Rep2>::value && - is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, - duration::type, _Period> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + !__is_duration<_Rep2>::value && is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration::type, _Period>> operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -typename common_type<_Rep1, _Rep2>::type +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr typename common_type<_Rep1, _Rep2>::type operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type, duration<_Rep2, _Period2> >::type _Ct; - return _Ct(__lhs).count() / _Ct(__rhs).count(); + typedef typename common_type, duration<_Rep2, _Period2>>::type _Ct; + return _Ct(__lhs).count() / _Ct(__rhs).count(); } // Duration % template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -__enable_if_t -< - !__is_duration<_Rep2>::value && - is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, - duration::type, _Period> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + !__is_duration<_Rep2>::value && is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration::type, _Period>> operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef duration<_Cr, _Period> _Cd; - return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef duration<_Cr, _Period> _Cd; + return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); } template -inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr -typename common_type, duration<_Rep2, _Period2> >::type -operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr + typename common_type, duration<_Rep2, _Period2>>::type + operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<_Rep1, _Rep2>::type _Cr; - typedef typename common_type, duration<_Rep2, _Period2> >::type _Cd; - return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); + typedef typename common_type<_Rep1, _Rep2>::type _Cr; + typedef typename common_type, duration<_Rep2, _Period2>>::type _Cd; + return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); } ////////////////////////////////////////////////////////// @@ -1375,214 +1395,210 @@ operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2 template class _LIBCUDACXX_TEMPLATE_VIS time_point { - static_assert(__is_duration<_Duration>::value, - "Second template parameter of time_point must be a std::chrono::duration"); -public: - typedef _Clock clock; - typedef _Duration duration; - typedef typename duration::rep rep; - typedef typename duration::period period; -private: - duration __d_; + static_assert(__is_duration<_Duration>::value, + "Second template parameter of time_point must be a std::chrono::duration"); public: - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 time_point() : __d_(duration::zero()) {} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit time_point(const duration& __d) : __d_(__d) {} - - // conversions - template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - time_point(const time_point& t, - __enable_if_t - < - is_convertible<_Duration2, duration>::value - >* = 0) - : __d_(t.time_since_epoch()) {} + typedef _Clock clock; + typedef _Duration duration; + typedef typename duration::rep rep; + typedef typename duration::period period; - // observer +private: + duration __d_; - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 duration time_since_epoch() const {return __d_;} +public: + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 time_point() + : __d_(duration::zero()) + {} + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit time_point(const duration& __d) + : __d_(__d) + {} + + // conversions + template + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 + time_point(const time_point& t, __enable_if_t::value>* = 0) + : __d_(t.time_since_epoch()) + {} + + // observer + + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 duration time_since_epoch() const + { + return __d_; + } - // arithmetic + // arithmetic - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 time_point& operator+=(const duration& __d) + { + __d_ += __d; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 time_point& operator-=(const duration& __d) + { + __d_ -= __d; + return *this; + } - // special values + // special values - _LIBCUDACXX_INLINE_VISIBILITY static constexpr time_point min() noexcept {return time_point(duration::min());} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr time_point max() noexcept {return time_point(duration::max());} + _LIBCUDACXX_INLINE_VISIBILITY static constexpr time_point min() noexcept + { + return time_point(duration::min()); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr time_point max() noexcept + { + return time_point(duration::max()); + } }; -} // chrono +} // namespace chrono template -struct _LIBCUDACXX_TEMPLATE_VIS common_type, - chrono::time_point<_Clock, _Duration2> > +struct _LIBCUDACXX_TEMPLATE_VIS + common_type, chrono::time_point<_Clock, _Duration2>> { - typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; + typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; }; -namespace chrono { +namespace chrono +{ template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -time_point<_Clock, _ToDuration> +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 time_point<_Clock, _ToDuration> time_point_cast(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>(_CUDA_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); + return time_point<_Clock, _ToDuration>(_CUDA_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); } #if _CCCL_STD_VER > 2011 template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t -< - __is_duration<_ToDuration>::value, - time_point<_Clock, _ToDuration> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t<__is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration>> floor(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; + return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; } template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t -< - __is_duration<_ToDuration>::value, - time_point<_Clock, _ToDuration> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t<__is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration>> ceil(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; + return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; } template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t -< - __is_duration<_ToDuration>::value, - time_point<_Clock, _ToDuration> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t<__is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration>> round(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; + return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; } template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t -< - numeric_limits<_Rep>::is_signed, - duration<_Rep, _Period> -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t::is_signed, duration<_Rep, _Period>> abs(duration<_Rep, _Period> __d) { - return __d >= __d.zero() ? +__d : -__d; + return __d >= __d.zero() ? +__d : -__d; } #endif // _CCCL_STD_VER > 2011 // time_point == template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -bool +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() == __rhs.time_since_epoch(); + return __lhs.time_since_epoch() == __rhs.time_since_epoch(); } // time_point != template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -bool +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__lhs == __rhs); + return !(__lhs == __rhs); } // time_point < template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -bool +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() < __rhs.time_since_epoch(); + return __lhs.time_since_epoch() < __rhs.time_since_epoch(); } // time_point > template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -bool +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __rhs < __lhs; + return __rhs < __lhs; } // time_point <= template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -bool +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__rhs < __lhs); + return !(__rhs < __lhs); } // time_point >= template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -bool +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return !(__lhs < __rhs); + return !(__lhs < __rhs); } // time_point operator+(time_point x, duration y); template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> -operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) + time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> + operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; - return _Tr (__lhs.time_since_epoch() + __rhs); + typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> _Tr; + return _Tr(__lhs.time_since_epoch() + __rhs); } // time_point operator+(duration x, time_point y); template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -time_point<_Clock, typename common_type, _Duration2>::type> -operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) + time_point<_Clock, typename common_type, _Duration2>::type> + operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __rhs + __lhs; + return __rhs + __lhs; } // time_point operator-(time_point x, duration y); template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> -operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) + time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> + operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; - return _Ret(__lhs.time_since_epoch() -__rhs); + typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> _Ret; + return _Ret(__lhs.time_since_epoch() - __rhs); } // duration operator-(time_point x, time_point y); template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 -typename common_type<_Duration1, _Duration2>::type +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 typename common_type<_Duration1, _Duration2>::type operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) { - return __lhs.time_since_epoch() - __rhs.time_since_epoch(); + return __lhs.time_since_epoch() - __rhs.time_since_epoch(); } ////////////////////////////////////////////////////////// @@ -1591,31 +1607,28 @@ operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, class _LIBCUDACXX_TYPE_VIS system_clock { public: - typedef _LIBCUDACXX_SYS_CLOCK_DURATION duration; - typedef duration::rep rep; - typedef duration::period period; - typedef chrono::time_point time_point; - static _CCCL_CONSTEXPR_CXX14 const bool is_steady = false; + typedef _LIBCUDACXX_SYS_CLOCK_DURATION duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point time_point; + static _CCCL_CONSTEXPR_CXX14 const bool is_steady = false; - _CCCL_HOST_DEVICE - static time_point now() noexcept; - _CCCL_HOST_DEVICE - static time_t to_time_t (const time_point& __t) noexcept; - _CCCL_HOST_DEVICE - static time_point from_time_t(time_t __t) noexcept; + _CCCL_HOST_DEVICE static time_point now() noexcept; + _CCCL_HOST_DEVICE static time_t to_time_t(const time_point& __t) noexcept; + _CCCL_HOST_DEVICE static time_point from_time_t(time_t __t) noexcept; }; #ifndef _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK class _LIBCUDACXX_TYPE_VIS steady_clock { public: - typedef nanoseconds duration; - typedef duration::rep rep; - typedef duration::period period; - typedef chrono::time_point time_point; - static _CCCL_CONSTEXPR_CXX14 const bool is_steady = true; + typedef nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef chrono::time_point time_point; + static _CCCL_CONSTEXPR_CXX14 const bool is_steady = true; - static time_point now() noexcept; + static time_point now() noexcept; }; typedef steady_clock high_resolution_clock; @@ -1628,489 +1641,594 @@ typedef system_clock high_resolution_clock; // [time.clock.file], type file_clock using file_clock = _CUDA_VSTD_FS::_FilesystemClock; -template +template using file_time = time_point; - template using sys_time = time_point; using sys_seconds = sys_time; using sys_days = sys_time; -struct local_t {}; -template -using local_time = time_point; +struct local_t +{}; +template +using local_time = time_point; using local_seconds = local_time; using local_days = local_time; -struct last_spec { explicit last_spec() = default; }; +struct last_spec +{ + explicit last_spec() = default; +}; -class day { +class day +{ private: - unsigned char __d; -public: - day() = default; - _LIBCUDACXX_INLINE_VISIBILITY - explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast(__val)) {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr day& operator++() noexcept { ++__d; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr day& operator--() noexcept { --__d; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr day& operator+=(const days& __dd) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr day& operator-=(const days& __dd) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - explicit inline constexpr operator unsigned() const noexcept { return __d; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } - }; + unsigned char __d; +public: + day() = default; + _LIBCUDACXX_INLINE_VISIBILITY explicit inline constexpr day(unsigned __val) noexcept + : __d(static_cast(__val)) + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr day& operator++() noexcept + { + ++__d; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr day operator++(int) noexcept + { + day __tmp = *this; + ++(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr day& operator--() noexcept + { + --__d; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr day operator--(int) noexcept + { + day __tmp = *this; + --(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr day& operator+=(const days& __dd) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr day& operator-=(const days& __dd) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY explicit inline constexpr operator unsigned() const noexcept + { + return __d; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __d >= 1 && __d <= 31; + } +}; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const day& __lhs, const day& __rhs) noexcept -{ return static_cast(__lhs) == static_cast(__rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const day& __lhs, const day& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator==(const day& __lhs, const day& __rhs) noexcept +{ + return static_cast(__lhs) == static_cast(__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const day& __lhs, const day& __rhs) noexcept -{ return static_cast(__lhs) < static_cast(__rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator!=(const day& __lhs, const day& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const day& __lhs, const day& __rhs) noexcept -{ return __rhs < __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<(const day& __lhs, const day& __rhs) noexcept +{ + return static_cast(__lhs) < static_cast(__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const day& __lhs, const day& __rhs) noexcept -{ return !(__rhs < __lhs);} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>(const day& __lhs, const day& __rhs) noexcept +{ + return __rhs < __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const day& __lhs, const day& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<=(const day& __lhs, const day& __rhs) noexcept +{ + return !(__rhs < __lhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -day operator+ (const day& __lhs, const days& __rhs) noexcept -{ return day(static_cast(__lhs) + static_cast(__rhs.count())); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>=(const day& __lhs, const day& __rhs) noexcept +{ + return !(__lhs < __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -day operator+ (const days& __lhs, const day& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr day operator+(const day& __lhs, const days& __rhs) noexcept +{ + return day(static_cast(__lhs) + static_cast(__rhs.count())); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -day operator- (const day& __lhs, const days& __rhs) noexcept -{ return __lhs + -__rhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr day operator+(const days& __lhs, const day& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -days operator-(const day& __lhs, const day& __rhs) noexcept -{ return days(static_cast(static_cast(__lhs)) - - static_cast(static_cast(__rhs))); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr day operator-(const day& __lhs, const days& __rhs) noexcept +{ + return __lhs + -__rhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr day& day::operator+=(const days& __dd) noexcept -{ *this = *this + __dd; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr days operator-(const day& __lhs, const day& __rhs) noexcept +{ + return days(static_cast(static_cast(__lhs)) - static_cast(static_cast(__rhs))); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr day& day::operator-=(const days& __dd) noexcept -{ *this = *this - __dd; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr day& day::operator+=(const days& __dd) noexcept +{ + *this = *this + __dd; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr day& day::operator-=(const days& __dd) noexcept +{ + *this = *this - __dd; + return *this; +} -class month { +class month +{ private: - unsigned char __m; + unsigned char __m; + public: - month() = default; - _LIBCUDACXX_INLINE_VISIBILITY - explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast(__val)) {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr month& operator++() noexcept { ++__m; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr month& operator--() noexcept { --__m; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr month& operator+=(const months& __m1) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr month& operator-=(const months& __m1) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - explicit inline constexpr operator unsigned() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; } + month() = default; + _LIBCUDACXX_INLINE_VISIBILITY explicit inline constexpr month(unsigned __val) noexcept + : __m(static_cast(__val)) + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr month& operator++() noexcept + { + ++__m; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr month operator++(int) noexcept + { + month __tmp = *this; + ++(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr month& operator--() noexcept + { + --__m; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr month operator--(int) noexcept + { + month __tmp = *this; + --(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr month& operator+=(const months& __m1) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr month& operator-=(const months& __m1) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY explicit inline constexpr operator unsigned() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __m >= 1 && __m <= 12; + } }; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept +{ + return static_cast(__lhs) == static_cast(__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const month& __lhs, const month& __rhs) noexcept -{ return static_cast(__lhs) == static_cast(__rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator!=(const month& __lhs, const month& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const month& __lhs, const month& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<(const month& __lhs, const month& __rhs) noexcept +{ + return static_cast(__lhs) < static_cast(__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const month& __lhs, const month& __rhs) noexcept -{ return static_cast(__lhs) < static_cast(__rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>(const month& __lhs, const month& __rhs) noexcept +{ + return __rhs < __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const month& __lhs, const month& __rhs) noexcept -{ return __rhs < __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<=(const month& __lhs, const month& __rhs) noexcept +{ + return !(__rhs < __lhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const month& __lhs, const month& __rhs) noexcept -{ return !(__rhs < __lhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>=(const month& __lhs, const month& __rhs) noexcept +{ + return !(__lhs < __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const month& __lhs, const month& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept +{ + auto const __mu = static_cast(static_cast(__lhs)) + (__rhs.count() - 1); + auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; + return month{static_cast(__mu - __yr * 12 + 1)}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month operator+ (const month& __lhs, const months& __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept { - auto const __mu = static_cast(static_cast(__lhs)) + (__rhs.count() - 1); - auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; - return month{static_cast(__mu - __yr * 12 + 1)}; + return __rhs + __lhs; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month operator+ (const months& __lhs, const month& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept +{ + return __lhs + -__rhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month operator- (const month& __lhs, const months& __rhs) noexcept -{ return __lhs + -__rhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept +{ + auto const __dm = static_cast(__lhs) - static_cast(__rhs); + return months(__dm <= 11 ? __dm : __dm + 12); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -months operator-(const month& __lhs, const month& __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month& month::operator+=(const months& __dm) noexcept { - auto const __dm = static_cast(__lhs) - static_cast(__rhs); - return months(__dm <= 11 ? __dm : __dm + 12); + *this = *this + __dm; + return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr month& month::operator+=(const months& __dm) noexcept -{ *this = *this + __dm; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month& month::operator-=(const months& __dm) noexcept +{ + *this = *this - __dm; + return *this; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr month& month::operator-=(const months& __dm) noexcept -{ *this = *this - __dm; return *this; } +class year +{ +private: + short __y; +public: + year() = default; + _LIBCUDACXX_INLINE_VISIBILITY explicit inline constexpr year(int __val) noexcept + : __y(static_cast(__val)) + {} -class year { -private: - short __y; -public: - year() = default; - _LIBCUDACXX_INLINE_VISIBILITY - explicit inline constexpr year(int __val) noexcept : __y(static_cast(__val)) {} - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year& operator++() noexcept { ++__y; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year& operator--() noexcept { --__y; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year& operator+=(const years& __dy) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year& operator-=(const years& __dy) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year operator+() const noexcept { return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year operator-() const noexcept { return year{-__y}; } - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); } - _LIBCUDACXX_INLINE_VISIBILITY - explicit inline constexpr operator int() const noexcept { return __y; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr bool ok() const noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - static inline constexpr year min() noexcept { return year{-32767}; } - _LIBCUDACXX_INLINE_VISIBILITY - static inline constexpr year max() noexcept { return year{ 32767}; } -}; - + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year& operator++() noexcept + { + ++__y; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year operator++(int) noexcept + { + year __tmp = *this; + ++(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year& operator--() noexcept + { + --__y; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year operator--(int) noexcept + { + year __tmp = *this; + --(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr year& operator+=(const years& __dy) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year& operator-=(const years& __dy) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year operator+() const noexcept + { + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year operator-() const noexcept + { + return year{-__y}; + } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const year& __lhs, const year& __rhs) noexcept -{ return static_cast(__lhs) == static_cast(__rhs); } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool is_leap() const noexcept + { + return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); + } + _LIBCUDACXX_INLINE_VISIBILITY explicit inline constexpr operator int() const noexcept + { + return __y; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool ok() const noexcept; + _LIBCUDACXX_INLINE_VISIBILITY static inline constexpr year min() noexcept + { + return year{-32767}; + } + _LIBCUDACXX_INLINE_VISIBILITY static inline constexpr year max() noexcept + { + return year{32767}; + } +}; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const year& __lhs, const year& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator==(const year& __lhs, const year& __rhs) noexcept +{ + return static_cast(__lhs) == static_cast(__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const year& __lhs, const year& __rhs) noexcept -{ return static_cast(__lhs) < static_cast(__rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator!=(const year& __lhs, const year& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const year& __lhs, const year& __rhs) noexcept -{ return __rhs < __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<(const year& __lhs, const year& __rhs) noexcept +{ + return static_cast(__lhs) < static_cast(__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const year& __lhs, const year& __rhs) noexcept -{ return !(__rhs < __lhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>(const year& __lhs, const year& __rhs) noexcept +{ + return __rhs < __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const year& __lhs, const year& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<=(const year& __lhs, const year& __rhs) noexcept +{ + return !(__rhs < __lhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year operator+ (const year& __lhs, const years& __rhs) noexcept -{ return year(static_cast(__lhs) + __rhs.count()); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>=(const year& __lhs, const year& __rhs) noexcept +{ + return !(__lhs < __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year operator+ (const years& __lhs, const year& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year operator+(const year& __lhs, const years& __rhs) noexcept +{ + return year(static_cast(__lhs) + __rhs.count()); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year operator- (const year& __lhs, const years& __rhs) noexcept -{ return __lhs + -__rhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year operator+(const years& __lhs, const year& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -years operator-(const year& __lhs, const year& __rhs) noexcept -{ return years{static_cast(__lhs) - static_cast(__rhs)}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year operator-(const year& __lhs, const years& __rhs) noexcept +{ + return __lhs + -__rhs; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr years operator-(const year& __lhs, const year& __rhs) noexcept +{ + return years{static_cast(__lhs) - static_cast(__rhs)}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year& year::operator+=(const years& __dy) noexcept -{ *this = *this + __dy; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year& year::operator+=(const years& __dy) noexcept +{ + *this = *this + __dy; + return *this; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year& year::operator-=(const years& __dy) noexcept -{ *this = *this - __dy; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year& year::operator-=(const years& __dy) noexcept +{ + *this = *this - __dy; + return *this; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr bool year::ok() const noexcept -{ return static_cast(min()) <= __y && __y <= static_cast(max()); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool year::ok() const noexcept +{ + return static_cast(min()) <= __y && __y <= static_cast(max()); +} class weekday_indexed; class weekday_last; -class weekday { +class weekday +{ private: - unsigned char __wd; + unsigned char __wd; + public: weekday() = default; - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast(__val == 7 ? 0 : __val)) {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr weekday(const sys_days& __sysd) noexcept - : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {} - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr weekday(const local_days& __locd) noexcept - : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {} - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr weekday& operator+=(const days& __dd) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr weekday& operator-=(const days& __dd) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr unsigned c_encoding() const noexcept { return __wd; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __wd <= 6; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr weekday_indexed operator[](unsigned __index) const noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr weekday_last operator[](last_spec) const noexcept; - - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr unsigned char __weekday_from_days(int __days) noexcept; -}; + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr weekday(unsigned __val) noexcept + : __wd(static_cast(__val == 7 ? 0 : __val)) + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday(const sys_days& __sysd) noexcept + : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) + {} + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr weekday(const local_days& __locd) noexcept + : __wd(__weekday_from_days(__locd.time_since_epoch().count())) + {} + + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday& operator++() noexcept + { + __wd = (__wd == 6 ? 0 : __wd + 1); + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday operator++(int) noexcept + { + weekday __tmp = *this; + ++(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday& operator--() noexcept + { + __wd = (__wd == 0 ? 6 : __wd - 1); + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday operator--(int) noexcept + { + weekday __tmp = *this; + --(*this); + return __tmp; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr weekday& operator+=(const days& __dd) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr weekday& operator-=(const days& __dd) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr unsigned c_encoding() const noexcept + { + return __wd; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr unsigned iso_encoding() const noexcept + { + return __wd == 0u ? 7 : __wd; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __wd <= 6; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr weekday_indexed operator[](unsigned __index) const noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr weekday_last operator[](last_spec) const noexcept; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr unsigned char __weekday_from_days(int __days) noexcept; +}; // https://howardhinnant.github.io/date_algorithms.html#weekday_from_days -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -unsigned char weekday::__weekday_from_days(int __days) noexcept +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr unsigned char weekday::__weekday_from_days(int __days) noexcept { - return static_cast( - static_cast(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6) - ); + return static_cast(static_cast(__days >= -4 ? (__days + 4) % 7 : (__days + 5) % 7 + 6)); } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept -{ return __lhs.c_encoding() == __rhs.c_encoding(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept +{ + return __lhs.c_encoding() == __rhs.c_encoding(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept -{ return __lhs.c_encoding() < __rhs.c_encoding(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept -{ return __rhs < __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<(const weekday& __lhs, const weekday& __rhs) noexcept +{ + return __lhs.c_encoding() < __rhs.c_encoding(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept -{ return !(__rhs < __lhs);} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>(const weekday& __lhs, const weekday& __rhs) noexcept +{ + return __rhs < __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept +{ + return !(__rhs < __lhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept { - auto const __mu = static_cast(__lhs.c_encoding()) + __rhs.count(); - auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; - return weekday{static_cast(__mu - __yr * 7)}; + return !(__lhs < __rhs); } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept +{ + auto const __mu = static_cast(__lhs.c_encoding()) + __rhs.count(); + auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; + return weekday{static_cast(__mu - __yr * 7)}; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept -{ return __lhs + -__rhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept { - // casts are required to work around nvcc bug 3145483 - const int __wdu = static_cast(__lhs.c_encoding()) - static_cast(__rhs.c_encoding()); - const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7; - return days{__wdu - __wk * 7}; + return __lhs + -__rhs; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept -{ *this = *this + __dd; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept +{ + // casts are required to work around nvcc bug 3145483 + const int __wdu = static_cast(__lhs.c_encoding()) - static_cast(__rhs.c_encoding()); + const int __wk = (__wdu >= 0 ? __wdu : __wdu - 6) / 7; + return days{__wdu - __wk * 7}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept -{ *this = *this - __dd; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept +{ + *this = *this + __dd; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept +{ + *this = *this - __dd; + return *this; +} -class weekday_indexed { +class weekday_indexed +{ private: - _CUDA_VSTD::chrono::weekday __wd; - unsigned char __idx; + _CUDA_VSTD::chrono::weekday __wd; + unsigned char __idx; + public: - weekday_indexed() = default; - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr weekday_indexed(const _CUDA_VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept - : __wd{__wdval}, __idx(static_cast(__idxval)) {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr _CUDA_VSTD::chrono::weekday weekday() const noexcept { return __wd; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr unsigned index() const noexcept { return __idx; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; } + weekday_indexed() = default; + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday_indexed( + const _CUDA_VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept + : __wd{__wdval} + , __idx(static_cast(__idxval)) + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr _CUDA_VSTD::chrono::weekday weekday() const noexcept + { + return __wd; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr unsigned index() const noexcept + { + return __idx; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __wd.ok() && __idx >= 1 && __idx <= 5; + } }; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept -{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept +{ + return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -class weekday_last { +class weekday_last +{ private: - _CUDA_VSTD::chrono::weekday __wd; + _CUDA_VSTD::chrono::weekday __wd; + public: - _LIBCUDACXX_INLINE_VISIBILITY - explicit constexpr weekday_last(const _CUDA_VSTD::chrono::weekday& __val) noexcept - : __wd{__val} {} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr _CUDA_VSTD::chrono::weekday weekday() const noexcept { return __wd; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr bool ok() const noexcept { return __wd.ok(); } + _LIBCUDACXX_INLINE_VISIBILITY explicit constexpr weekday_last(const _CUDA_VSTD::chrono::weekday& __val) noexcept + : __wd{__val} + {} + _LIBCUDACXX_INLINE_VISIBILITY constexpr _CUDA_VSTD::chrono::weekday weekday() const noexcept + { + return __wd; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool ok() const noexcept + { + return __wd.ok(); + } }; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept -{ return __lhs.weekday() == __rhs.weekday(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept +{ + return __lhs.weekday() == __rhs.weekday(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday_indexed weekday::operator[](unsigned __index) const noexcept +{ + return weekday_indexed{*this, __index}; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr weekday_last weekday::operator[](last_spec) const noexcept +{ + return weekday_last{*this}; +} _LIBCUDACXX_INLINE_VAR constexpr last_spec last{}; -_LIBCUDACXX_INLINE_VAR constexpr weekday Sunday{0}; -_LIBCUDACXX_INLINE_VAR constexpr weekday Monday{1}; -_LIBCUDACXX_INLINE_VAR constexpr weekday Tuesday{2}; -_LIBCUDACXX_INLINE_VAR constexpr weekday Wednesday{3}; -_LIBCUDACXX_INLINE_VAR constexpr weekday Thursday{4}; -_LIBCUDACXX_INLINE_VAR constexpr weekday Friday{5}; -_LIBCUDACXX_INLINE_VAR constexpr weekday Saturday{6}; +_LIBCUDACXX_INLINE_VAR constexpr weekday Sunday{0}; +_LIBCUDACXX_INLINE_VAR constexpr weekday Monday{1}; +_LIBCUDACXX_INLINE_VAR constexpr weekday Tuesday{2}; +_LIBCUDACXX_INLINE_VAR constexpr weekday Wednesday{3}; +_LIBCUDACXX_INLINE_VAR constexpr weekday Thursday{4}; +_LIBCUDACXX_INLINE_VAR constexpr weekday Friday{5}; +_LIBCUDACXX_INLINE_VAR constexpr weekday Saturday{6}; _LIBCUDACXX_INLINE_VAR constexpr month January{1}; _LIBCUDACXX_INLINE_VAR constexpr month February{2}; @@ -2125,1085 +2243,1363 @@ _LIBCUDACXX_INLINE_VAR constexpr month October{10}; _LIBCUDACXX_INLINE_VAR constexpr month November{11}; _LIBCUDACXX_INLINE_VAR constexpr month December{12}; - -class month_day { +class month_day +{ private: - chrono::month __m; - chrono::day __d; + chrono::month __m; + chrono::day __d; + public: - month_day() = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept - : __m{__mval}, __d{__dval} {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::day day() const noexcept { return __d; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr bool ok() const noexcept; + month_day() = default; + _LIBCUDACXX_INLINE_VISIBILITY constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept + : __m{__mval} + , __d{__dval} + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::day day() const noexcept + { + return __d; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool ok() const noexcept; }; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool month_day::ok() const noexcept -{ - if (!__m.ok()) return false; - const unsigned __dval = static_cast(__d); - if (__dval < 1 || __dval > 31) return false; - if (__dval <= 29) return true; -// Now we've got either 30 or 31 - const unsigned __mval = static_cast(__m); - if (__mval == 2) return false; - if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) - return __dval == 30; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool month_day::ok() const noexcept +{ + if (!__m.ok()) + { + return false; + } + const unsigned __dval = static_cast(__d); + if (__dval < 1 || __dval > 31) + { + return false; + } + if (__dval <= 29) + { return true; + } + // Now we've got either 30 or 31 + const unsigned __mval = static_cast(__m); + if (__mval == 2) + { + return false; + } + if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) + { + return __dval == 30; + } + return true; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept -{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept +{ + return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_day operator/(const month& __lhs, const day& __rhs) noexcept -{ return month_day{__lhs, __rhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_day operator/(const month& __lhs, const day& __rhs) noexcept +{ + return month_day{__lhs, __rhs}; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr -month_day operator/(const day& __lhs, const month& __rhs) noexcept -{ return __rhs / __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr month_day operator/(const day& __lhs, const month& __rhs) noexcept +{ + return __rhs / __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_day operator/(const month& __lhs, int __rhs) noexcept -{ return __lhs / day(__rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept +{ + return __lhs / day(__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr -month_day operator/(int __lhs, const day& __rhs) noexcept -{ return month(__lhs) / __rhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr month_day operator/(int __lhs, const day& __rhs) noexcept +{ + return month(__lhs) / __rhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr -month_day operator/(const day& __lhs, int __rhs) noexcept -{ return month(__rhs) / __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr month_day operator/(const day& __lhs, int __rhs) noexcept +{ + return month(__rhs) / __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<(const month_day& __lhs, const month_day& __rhs) noexcept +{ + return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>(const month_day& __lhs, const month_day& __rhs) noexcept +{ + return __rhs < __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept +{ + return !(__rhs < __lhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept +{ + return !(__lhs < __rhs); +} + +class month_day_last +{ +private: + chrono::month __m; + +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit constexpr month_day_last(const chrono::month& __val) noexcept + : __m{__val} + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __m.ok(); + } +}; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ + return __lhs.month() == __rhs.month(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept -{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept -{ return __rhs < __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator<(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ + return __lhs.month() < __rhs.month(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept -{ return !(__rhs < __lhs);} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ + return __rhs < __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept -{ return !(__lhs < __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ + return !(__rhs < __lhs); +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ + return !(__lhs < __rhs); +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept +{ + return month_day_last{__lhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept +{ + return month_day_last{__rhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept +{ + return month_day_last{month(__lhs)}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept +{ + return month_day_last{month(__rhs)}; +} -class month_day_last { +class month_weekday +{ private: - chrono::month __m; + chrono::month __m; + chrono::weekday_indexed __wdi; + public: - _LIBCUDACXX_INLINE_VISIBILITY - explicit constexpr month_day_last(const chrono::month& __val) noexcept - : __m{__val} {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __m.ok(); } + month_weekday() = default; + _LIBCUDACXX_INLINE_VISIBILITY constexpr month_weekday( + const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept + : __m{__mval} + , __wdi{__wdival} + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept + { + return __wdi; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __m.ok() && __wdi.ok(); + } }; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return __lhs.month() == __rhs.month(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return __lhs.month() < __rhs.month(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return !(__rhs < __lhs);} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept -{ return !(__lhs < __rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_day_last operator/(const month& __lhs, last_spec) noexcept -{ return month_day_last{__lhs}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_day_last operator/(last_spec, const month& __rhs) noexcept -{ return month_day_last{__rhs}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_day_last operator/(int __lhs, last_spec) noexcept -{ return month_day_last{month(__lhs)}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_day_last operator/(last_spec, int __rhs) noexcept -{ return month_day_last{month(__rhs)}; } - - -class month_weekday { +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept +{ + return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept +{ + return !(__lhs == __rhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday +operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept +{ + return month_weekday{__lhs, __rhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept +{ + return month_weekday{month(__lhs), __rhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday +operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept +{ + return month_weekday{__rhs, __lhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept +{ + return month_weekday{month(__rhs), __lhs}; +} + +class month_weekday_last +{ + chrono::month __m; + chrono::weekday_last __wdl; + +public: + _LIBCUDACXX_INLINE_VISIBILITY constexpr month_weekday_last( + const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept + : __m{__mval} + , __wdl{__wdlval} + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::weekday_last weekday_last() const noexcept + { + return __wdl; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __m.ok() && __wdl.ok(); + } +}; + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept +{ + return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept +{ + return !(__lhs == __rhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday_last +operator/(const month& __lhs, const weekday_last& __rhs) noexcept +{ + return month_weekday_last{__lhs, __rhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday_last +operator/(int __lhs, const weekday_last& __rhs) noexcept +{ + return month_weekday_last{month(__lhs), __rhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday_last +operator/(const weekday_last& __lhs, const month& __rhs) noexcept +{ + return month_weekday_last{__rhs, __lhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr month_weekday_last +operator/(const weekday_last& __lhs, int __rhs) noexcept +{ + return month_weekday_last{month(__rhs), __lhs}; +} + +class year_month +{ + chrono::year __y; + chrono::month __m; + +public: + year_month() = default; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept + : __y{__yval} + , __m{__mval} + {} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::year year() const noexcept + { + return __y; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month& operator+=(const months& __dm) noexcept + { + this->__m += __dm; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month& operator-=(const months& __dm) noexcept + { + this->__m -= __dm; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month& operator+=(const years& __dy) noexcept + { + this->__y += __dy; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month& operator-=(const years& __dy) noexcept + { + this->__y -= __dy; + return *this; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __y.ok() && __m.ok(); + } +}; + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month operator/(const year& __y, const month& __m) noexcept +{ + return year_month{__y, __m}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month operator/(const year& __y, int __m) noexcept +{ + return year_month{__y, month(__m)}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept +{ + return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept +{ + return !(__lhs == __rhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<(const year_month& __lhs, const year_month& __rhs) noexcept +{ + return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>(const year_month& __lhs, const year_month& __rhs) noexcept +{ + return __rhs < __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept +{ + return !(__rhs < __lhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept +{ + return !(__lhs < __rhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept +{ + int __dmi = static_cast(static_cast(__lhs.month())) - 1 + __rhs.count(); + const int __dy = (__dmi >= 0 ? __dmi : __dmi - 11) / 12; + __dmi = __dmi - __dy * 12 + 1; + return (__lhs.year() + years(__dy)) / month(static_cast(__dmi)); +} + +_LIBCUDACXX_INLINE_VISIBILITY constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept +{ + return __rhs + __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept +{ + return (__lhs.year() + __rhs) / __lhs.month(); +} + +_LIBCUDACXX_INLINE_VISIBILITY constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept +{ + return __rhs + __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept +{ + return (__lhs.year() - __rhs.year()) + + months(static_cast(__lhs.month()) - static_cast(__rhs.month())); +} + +_LIBCUDACXX_INLINE_VISIBILITY constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept +{ + return __lhs + -__rhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept +{ + return __lhs + -__rhs; +} + +class year_month_day_last; + +class year_month_day +{ private: - chrono::month __m; - chrono::weekday_indexed __wdi; + chrono::year __y; + chrono::month __m; + chrono::day __d; + public: - month_weekday() = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept - : __m{__mval}, __wdi{__wdival} {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); } + year_month_day() = default; + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day( + const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept + : __y{__yval} + , __m{__mval} + , __d{__dval} + {} + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day(const sys_days& __sysd) noexcept + : year_month_day(__from_days(__sysd.time_since_epoch())) + {} + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr year_month_day(const local_days& __locd) noexcept + : year_month_day(__from_days(__locd.time_since_epoch())) + {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day& operator+=(const months& __dm) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day& operator-=(const months& __dm) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day& operator+=(const years& __dy) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day& operator-=(const years& __dy) noexcept; + + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::year year() const noexcept + { + return __y; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::day day() const noexcept + { + return __d; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr operator sys_days() const noexcept + { + return sys_days{__to_days()}; + } + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr operator local_days() const noexcept + { + return local_days{__to_days()}; + } + + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool ok() const noexcept; + + _LIBCUDACXX_INLINE_VISIBILITY static constexpr year_month_day __from_days(days __d) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr days __to_days() const noexcept; }; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept -{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } +// https://howardhinnant.github.io/date_algorithms.html#civil_from_days +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day year_month_day::__from_days(days __d) noexcept +{ + static_assert(std::numeric_limits::digits >= 18, ""); + static_assert(std::numeric_limits::digits >= 20, ""); + const int __z = __d.count() + 719468; + const int __era = (__z >= 0 ? __z : __z - 146096) / 146097; + const unsigned __doe = static_cast(__z - __era * 146097); // [0, 146096] + const unsigned __yoe = (__doe - __doe / 1460 + __doe / 36524 - __doe / 146096) / 365; // [0, 399] + const int __yr = static_cast(__yoe) + __era * 400; + const unsigned __doy = __doe - (365 * __yoe + __yoe / 4 - __yoe / 100); // [0, 365] + const unsigned __mp = (5 * __doy + 2) / 153; // [0, 11] + const unsigned __dy = __doy - (153 * __mp + 2) / 5 + 1; // [1, 31] + const unsigned __mth = __mp + static_cast(__mp < 10 ? 3 : -9); // [1, 12] + return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}}; +} + +// https://howardhinnant.github.io/date_algorithms.html#days_from_civil +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr days year_month_day::__to_days() const noexcept +{ + static_assert(std::numeric_limits::digits >= 18, ""); + static_assert(std::numeric_limits::digits >= 20, ""); + + // nvcc doesn't allow ODR using constexpr globals. Therefore, + // make a temporary initialized from the global + auto constexpr __Feb = February; + const int __yr = static_cast(__y) - (__m <= __Feb); + const unsigned __mth = static_cast(__m); + const unsigned __dy = static_cast(__d); + + const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; + const unsigned __yoe = static_cast(__yr - __era * 400); // [0, 399] + const unsigned __doy = + static_cast((153 * (__mth + static_cast(__mth > 2 ? -3 : 9)) + 2) / 5 + __dy - 1); // [0, 365] + const unsigned __doe = __yoe * 365 + __yoe / 4 - __yoe / 100 + __doy; // [0, 146096] + return days{__era * 146097 + static_cast(__doe) - 719468}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + return !(__lhs == __rhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator<(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + if (__lhs.year() < __rhs.year()) + { + return true; + } + if (__lhs.year() > __rhs.year()) + { + return false; + } + if (__lhs.month() < __rhs.month()) + { + return true; + } + if (__lhs.month() > __rhs.month()) + { + return false; + } + return __lhs.day() < __rhs.day(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + return __rhs < __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept -{ return month_weekday{__lhs, __rhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + return !(__rhs < __lhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept -{ return month_weekday{month(__lhs), __rhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + return !(__lhs < __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept -{ return month_weekday{__rhs, __lhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator/(const year_month& __lhs, const day& __rhs) noexcept +{ + return year_month_day{__lhs.year(), __lhs.month(), __rhs}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept -{ return month_weekday{month(__rhs), __lhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day operator/(const year_month& __lhs, int __rhs) noexcept +{ + return __lhs / day(__rhs); +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator/(const year& __lhs, const month_day& __rhs) noexcept +{ + return __lhs / __rhs.month() / __rhs.day(); +} -class month_weekday_last { - chrono::month __m; - chrono::weekday_last __wdl; - public: - _LIBCUDACXX_INLINE_VISIBILITY - constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept - : __m{__mval}, __wdl{__wdlval} {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day operator/(int __lhs, const month_day& __rhs) noexcept +{ + return year(__lhs) / __rhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator/(const month_day& __lhs, const year& __rhs) noexcept +{ + return __rhs / __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day operator/(const month_day& __lhs, int __rhs) noexcept +{ + return year(__rhs) / __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator+(const year_month_day& __lhs, const months& __rhs) noexcept +{ + return (__lhs.year() / __lhs.month() + __rhs) / __lhs.day(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator+(const months& __lhs, const year_month_day& __rhs) noexcept +{ + return __rhs + __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator-(const year_month_day& __lhs, const months& __rhs) noexcept +{ + return __lhs + -__rhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator+(const year_month_day& __lhs, const years& __rhs) noexcept +{ + return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator+(const years& __lhs, const year_month_day& __rhs) noexcept +{ + return __rhs + __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day +operator-(const year_month_day& __lhs, const years& __rhs) noexcept +{ + return __lhs + -__rhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept +{ + *this = *this + __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept +{ + *this = *this - __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept +{ + *this = *this + __dy; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept +{ + *this = *this - __dy; + return *this; +} + +class year_month_day_last +{ +private: + chrono::year __y; + chrono::month_day_last __mdl; + +public: + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day_last( + const year& __yval, const month_day_last& __mdlval) noexcept + : __y{__yval} + , __mdl{__mdlval} + {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day_last& operator+=(const months& __m) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day_last& operator-=(const months& __m) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day_last& operator+=(const years& __y) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_day_last& operator-=(const years& __y) noexcept; + + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::year year() const noexcept + { + return __y; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __mdl.month(); + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month_day_last month_day_last() const noexcept + { + return __mdl; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::day day() const noexcept; + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr operator sys_days() const noexcept + { + return sys_days{year() / month() / day()}; + } + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr operator local_days() const noexcept + { + return local_days{year() / month() / day()}; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __y.ok() && __mdl.ok(); + } }; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept -{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::day year_month_day_last::day() const noexcept +{ + constexpr chrono::day __d[] = { + chrono::day(31), + chrono::day(28), + chrono::day(31), + chrono::day(30), + chrono::day(31), + chrono::day(30), + chrono::day(31), + chrono::day(31), + chrono::day(30), + chrono::day(31), + chrono::day(30), + chrono::day(31)}; + + // nvcc doesn't allow ODR using constexpr globals. Therefore, + // make a temporary initialized from the global + auto constexpr __Feb = February; + return month() != __Feb || !__y.is_leap() ? __d[static_cast(month()) - 1] : chrono::day{29}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept -{ return month_weekday_last{__lhs, __rhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator<(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + if (__lhs.year() < __rhs.year()) + { + return true; + } + if (__lhs.year() > __rhs.year()) + { + return false; + } + return __lhs.month_day_last() < __rhs.month_day_last(); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator>(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + return __rhs < __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + return !(__rhs < __lhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + return !(__lhs < __rhs); +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept +{ + return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator/(const year& __lhs, const month_day_last& __rhs) noexcept +{ + return year_month_day_last{__lhs, __rhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator/(int __lhs, const month_day_last& __rhs) noexcept +{ + return year_month_day_last{year{__lhs}, __rhs}; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator/(const month_day_last& __lhs, const year& __rhs) noexcept +{ + return __rhs / __lhs; +} + +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator/(const month_day_last& __lhs, int __rhs) noexcept +{ + return year{__rhs} / __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept -{ return month_weekday_last{month(__lhs), __rhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept +{ + return (__lhs.year() / __lhs.month() + __rhs) / last; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept -{ return month_weekday_last{__rhs, __lhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept -{ return month_weekday_last{month(__rhs), __lhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept +{ + return __lhs + (-__rhs); +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept +{ + return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; +} -class year_month { - chrono::year __y; - chrono::month __m; -public: - year_month() = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept - : __y{__yval}, __m{__mval} {} - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::year year() const noexcept { return __y; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); } -}; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last +operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept +{ + return __lhs + (-__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last& +year_month_day_last::operator+=(const months& __dm) noexcept +{ + *this = *this + __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last& +year_month_day_last::operator-=(const months& __dm) noexcept +{ + *this = *this - __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last& +year_month_day_last::operator+=(const years& __dy) noexcept +{ + *this = *this + __dy; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day_last& +year_month_day_last::operator-=(const years& __dy) noexcept +{ + *this = *this - __dy; + return *this; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept -{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept + : __y{__ymdl.year()} + , __m{__ymdl.month()} + , __d{__ymdl.day()} +{} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept -{ return !(__lhs == __rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool year_month_day::ok() const noexcept +{ + if (!__y.ok() || !__m.ok()) + { + return false; + } + return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept -{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); } +class year_month_weekday +{ + chrono::year __y; + chrono::month __m; + chrono::weekday_indexed __wdi; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept -{ return __rhs < __lhs; } +public: + year_month_weekday() = default; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday( + const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept + : __y{__yval} + , __m{__mval} + , __wdi{__wdival} + {} + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday(const sys_days& __sysd) noexcept + : year_month_weekday(__from_days(__sysd.time_since_epoch())) + {} + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept + : year_month_weekday(__from_days(__locd.time_since_epoch())) + {} + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday& operator+=(const months& m) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday& operator-=(const months& m) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday& operator+=(const years& y) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday& operator-=(const years& y) noexcept; + + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::year year() const noexcept + { + return __y; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::weekday weekday() const noexcept + { + return __wdi.weekday(); + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr unsigned index() const noexcept + { + return __wdi.index(); + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept + { + return __wdi; + } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept -{ return !(__rhs < __lhs);} + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr operator sys_days() const noexcept + { + return sys_days{__to_days()}; + } + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr operator local_days() const noexcept + { + return local_days{__to_days()}; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + if (!__y.ok() || !__m.ok() || !__wdi.ok()) + { + return false; + } + // TODO: make sure it's a valid date + return true; + } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept -{ return !(__lhs < __rhs); } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr year_month_weekday __from_days(days __d) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr days __to_days() const noexcept; +}; -_LIBCUDACXX_INLINE_VISIBILITY -constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday year_month_weekday::__from_days(days __d) noexcept { - int __dmi = static_cast(static_cast(__lhs.month())) - 1 + __rhs.count(); - const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12; - __dmi = __dmi - __dy * 12 + 1; - return (__lhs.year() + years(__dy)) / month(static_cast(__dmi)); + const sys_days __sysd{__d}; + const chrono::weekday __wd = chrono::weekday(__sysd); + const year_month_day __ymd = year_month_day(__sysd); + return year_month_weekday{__ymd.year(), __ymd.month(), __wd[(static_cast(__ymd.day()) - 1) / 7 + 1]}; } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr days year_month_weekday::__to_days() const noexcept +{ + const sys_days __sysd = sys_days(__y / __m / 1); + return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index() - 1) * 7})).time_since_epoch(); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept -{ return (__lhs.year() + __rhs) / __lhs.month(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept +{ + return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() + && __lhs.weekday_indexed() == __rhs.weekday_indexed(); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept -{ return (__lhs.year() - __rhs.year()) + months(static_cast(__lhs.month()) - static_cast(__rhs.month())); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept +{ + return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept -{ return __lhs + -__rhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator/(const year& __lhs, const month_weekday& __rhs) noexcept +{ + return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept -{ return __lhs + -__rhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator/(int __lhs, const month_weekday& __rhs) noexcept +{ + return year(__lhs) / __rhs; +} -class year_month_day_last; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator/(const month_weekday& __lhs, const year& __rhs) noexcept +{ + return __rhs / __lhs; +} -class year_month_day { -private: - chrono::year __y; - chrono::month __m; - chrono::day __d; -public: - year_month_day() = default; - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year_month_day( - const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept - : __y{__yval}, __m{__mval}, __d{__dval} {} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr year_month_day(const sys_days& __sysd) noexcept - : year_month_day(__from_days(__sysd.time_since_epoch())) {} - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr year_month_day(const local_days& __locd) noexcept - : year_month_day(__from_days(__locd.time_since_epoch())) {} - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day& operator+=(const months& __dm) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day& operator-=(const months& __dm) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day& operator+=(const years& __dy) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day& operator-=(const years& __dy) noexcept; - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::year year() const noexcept { return __y; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::day day() const noexcept { return __d; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr bool ok() const noexcept; - - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr year_month_day __from_days(days __d) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr days __to_days() const noexcept; -}; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator/(const month_weekday& __lhs, int __rhs) noexcept +{ + return year(__rhs) / __lhs; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept +{ + return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); +} -// https://howardhinnant.github.io/date_algorithms.html#civil_from_days -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day -year_month_day::__from_days(days __d) noexcept -{ - static_assert(std::numeric_limits::digits >= 18, ""); - static_assert(std::numeric_limits::digits >= 20 , ""); - const int __z = __d.count() + 719468; - const int __era = (__z >= 0 ? __z : __z - 146096) / 146097; - const unsigned __doe = static_cast(__z - __era * 146097); // [0, 146096] - const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399] - const int __yr = static_cast(__yoe) + __era * 400; - const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365] - const unsigned __mp = (5 * __doy + 2)/153; // [0, 11] - const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31] - const unsigned __mth = __mp + static_cast(__mp < 10 ? 3 : -9); // [1, 12] - return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}}; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept +{ + return __rhs + __lhs; } -// https://howardhinnant.github.io/date_algorithms.html#days_from_civil -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr days year_month_day::__to_days() const noexcept -{ - static_assert(std::numeric_limits::digits >= 18, ""); - static_assert(std::numeric_limits::digits >= 20 , ""); - - // nvcc doesn't allow ODR using constexpr globals. Therefore, - // make a temporary initialized from the global - auto constexpr __Feb = February; - const int __yr = static_cast(__y) - (__m <= __Feb); - const unsigned __mth = static_cast(__m); - const unsigned __dy = static_cast(__d); - - const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; - const unsigned __yoe = static_cast(__yr - __era * 400); // [0, 399] - const unsigned __doy = static_cast( - (153 * (__mth + static_cast(__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1); // [0, 365] - const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096] - return days{__era * 146097 + static_cast(__doe) - 719468}; -} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ - if (__lhs.year() < __rhs.year()) return true; - if (__lhs.year() > __rhs.year()) return false; - if (__lhs.month() < __rhs.month()) return true; - if (__lhs.month() > __rhs.month()) return false; - return __lhs.day() < __rhs.day(); -} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return !(__rhs < __lhs);} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept -{ return !(__lhs < __rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept -{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator/(const year_month& __lhs, int __rhs) noexcept -{ return __lhs / day(__rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept -{ return __lhs / __rhs.month() / __rhs.day(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator/(int __lhs, const month_day& __rhs) noexcept -{ return year(__lhs) / __rhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept -{ return __rhs / __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator/(const month_day& __lhs, int __rhs) noexcept -{ return year(__rhs) / __lhs; } - - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept -{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept -{ return __rhs + __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept -{ return __lhs + -__rhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept -{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept -{ return __rhs + __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept -{ return __lhs + -__rhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } - -class year_month_day_last { -private: - chrono::year __y; - chrono::month_day_last __mdl; -public: - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept - : __y{__yval}, __mdl{__mdlval} {} - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day_last& operator+=(const months& __m) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day_last& operator-=(const months& __m) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day_last& operator+=(const years& __y) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_day_last& operator-=(const years& __y) noexcept; - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::year year() const noexcept { return __y; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __mdl.month(); } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::day day() const noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; } - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); } -}; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept +{ + return __lhs + (-__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -chrono::day year_month_day_last::day() const noexcept +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept { - constexpr chrono::day __d[] = - { - chrono::day(31), chrono::day(28), chrono::day(31), - chrono::day(30), chrono::day(31), chrono::day(30), - chrono::day(31), chrono::day(31), chrono::day(30), - chrono::day(31), chrono::day(30), chrono::day(31) - }; + return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; +} - // nvcc doesn't allow ODR using constexpr globals. Therefore, - // make a temporary initialized from the global - auto constexpr __Feb = February; - return month() != __Feb || !__y.is_leap() ? - __d[static_cast(month()) - 1] : chrono::day{29}; -} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept -{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept -{ - if (__lhs.year() < __rhs.year()) return true; - if (__lhs.year() > __rhs.year()) return false; - return __lhs.month_day_last() < __rhs.month_day_last(); -} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept -{ return __rhs < __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept -{ return !(__rhs < __lhs);} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept -{ return !(__lhs < __rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept -{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept -{ return year_month_day_last{__lhs, __rhs}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept -{ return year_month_day_last{year{__lhs}, __rhs}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept -{ return __rhs / __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept -{ return year{__rhs} / __lhs; } - - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept -{ return (__lhs.year() / __lhs.month() + __rhs) / last; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept -{ return __rhs + __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept -{ return __lhs + (-__rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept -{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept -{ return __rhs + __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept -{ return __lhs + (-__rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept - : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr bool year_month_day::ok() const noexcept -{ - if (!__y.ok() || !__m.ok()) return false; - return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); -} - -class year_month_weekday { - chrono::year __y; - chrono::month __m; - chrono::weekday_indexed __wdi; -public: - year_month_weekday() = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval, - const chrono::weekday_indexed& __wdival) noexcept - : __y{__yval}, __m{__mval}, __wdi{__wdival} {} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday(const sys_days& __sysd) noexcept - : year_month_weekday(__from_days(__sysd.time_since_epoch())) {} - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept - : year_month_weekday(__from_days(__locd.time_since_epoch())) {} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday& operator+=(const months& m) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday& operator-=(const months& m) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday& operator+=(const years& y) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday& operator-=(const years& y) noexcept; - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::year year() const noexcept { return __y; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr unsigned index() const noexcept { return __wdi.index(); } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept - { - if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false; - // TODO: make sure it's a valid date - return true; - } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday +operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept +{ + return __lhs + (-__rhs); +} - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr year_month_weekday __from_days(days __d) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr days __to_days() const noexcept; -}; +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday& +year_month_weekday::operator+=(const months& __dm) noexcept +{ + *this = *this + __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday& +year_month_weekday::operator-=(const months& __dm) noexcept +{ + *this = *this - __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday& +year_month_weekday::operator+=(const years& __dy) noexcept +{ + *this = *this + __dy; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday& +year_month_weekday::operator-=(const years& __dy) noexcept +{ + *this = *this - __dy; + return *this; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday year_month_weekday::__from_days(days __d) noexcept -{ - const sys_days __sysd{__d}; - const chrono::weekday __wd = chrono::weekday(__sysd); - const year_month_day __ymd = year_month_day(__sysd); - return year_month_weekday{__ymd.year(), __ymd.month(), - __wd[(static_cast(__ymd.day())-1)/7+1]}; -} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -days year_month_weekday::__to_days() const noexcept -{ - const sys_days __sysd = sys_days(__y/__m/1); - return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7})) - .time_since_epoch(); -} - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept -{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept -{ return !(__lhs == __rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept -{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept -{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept -{ return year(__lhs) / __rhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept -{ return __rhs / __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept -{ return year(__rhs) / __lhs; } - - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept -{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept -{ return __rhs + __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept -{ return __lhs + (-__rhs); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept -{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept -{ return __rhs + __lhs; } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept -{ return __lhs + (-__rhs); } - - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } - -class year_month_weekday_last { +class year_month_weekday_last +{ private: - chrono::year __y; - chrono::month __m; - chrono::weekday_last __wdl; + chrono::year __y; + chrono::month __m; + chrono::weekday_last __wdl; + public: - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval, - const chrono::weekday_last& __wdlval) noexcept - : __y{__yval}, __m{__mval}, __wdl{__wdlval} {} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; - - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::year year() const noexcept { return __y; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::month month() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } - _LIBCUDACXX_INLINE_VISIBILITY - inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } - _LIBCUDACXX_INLINE_VISIBILITY - inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); } - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr days __to_days() const noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday_last( + const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept + : __y{__yval} + , __m{__mval} + , __wdl{__wdlval} + {} + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; + _LIBCUDACXX_INLINE_VISIBILITY constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; + + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::year year() const noexcept + { + return __y; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::month month() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::weekday weekday() const noexcept + { + return __wdl.weekday(); + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr chrono::weekday_last weekday_last() const noexcept + { + return __wdl; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr operator sys_days() const noexcept + { + return sys_days{__to_days()}; + } + _LIBCUDACXX_INLINE_VISIBILITY inline explicit constexpr operator local_days() const noexcept + { + return local_days{__to_days()}; + } + _LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool ok() const noexcept + { + return __y.ok() && __m.ok() && __wdl.ok(); + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr days __to_days() const noexcept; }; -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -days year_month_weekday_last::__to_days() const noexcept +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr days year_month_weekday_last::__to_days() const noexcept { - const sys_days __last = sys_days{__y/__m/last}; - return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch(); - + const sys_days __last = sys_days{__y / __m / last}; + return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch(); } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept -{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } - -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept -{ return !(__lhs == __rhs); } - +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept +{ + return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept -{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr bool +operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept +{ + return !(__lhs == __rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept -{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept +{ + return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept -{ return year(__lhs) / __rhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept +{ + return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept -{ return __rhs / __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator/(int __lhs, const month_weekday_last& __rhs) noexcept +{ + return year(__lhs) / __rhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept -{ return year(__rhs) / __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept +{ + return __rhs / __lhs; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator/(const month_weekday_last& __lhs, int __rhs) noexcept +{ + return year(__rhs) / __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept -{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept +{ + return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept -{ return __lhs + (-__rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept +{ + return __lhs + (-__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept -{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept +{ + return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept -{ return __rhs + __lhs; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept +{ + return __rhs + __lhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr -year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept -{ return __lhs + (-__rhs); } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last +operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept +{ + return __lhs + (-__rhs); +} -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } -_LIBCUDACXX_INLINE_VISIBILITY -inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last& +year_month_weekday_last::operator+=(const months& __dm) noexcept +{ + *this = *this + __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last& +year_month_weekday_last::operator-=(const months& __dm) noexcept +{ + *this = *this - __dm; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last& +year_month_weekday_last::operator+=(const years& __dy) noexcept +{ + *this = *this + __dy; + return *this; +} +_LIBCUDACXX_INLINE_VISIBILITY inline constexpr year_month_weekday_last& +year_month_weekday_last::operator-=(const years& __dy) noexcept +{ + *this = *this - __dy; + return *this; +} -_CCCL_NODISCARD inline _LIBCUDACXX_INLINE_VISIBILITY -constexpr unsigned __hh_mm_ss_width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0) +_CCCL_NODISCARD inline _LIBCUDACXX_INLINE_VISIBILITY constexpr unsigned +__hh_mm_ss_width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0) { - if (__n >= 2 && __d != 0 && __w < 19) - return 1 + __hh_mm_ss_width(__n, __d % __n * 10, __w+1); - return 0; + if (__n >= 2 && __d != 0 && __w < 19) + { + return 1 + __hh_mm_ss_width(__n, __d % __n * 10, __w + 1); + } + return 0; } template class hh_mm_ss { private: - static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration"); - using __CommonType = typename common_type<_Duration, chrono::seconds>::type; + static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration"); + using __CommonType = typename common_type<_Duration, chrono::seconds>::type; - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr uint64_t __pow10(unsigned __exp) + _LIBCUDACXX_INLINE_VISIBILITY static constexpr uint64_t __pow10(unsigned __exp) + { + uint64_t __ret = 1; + for (unsigned __i = 0; __i < __exp; ++__i) { - uint64_t __ret = 1; - for (unsigned __i = 0; __i < __exp; ++__i) - __ret *= 10U; - return __ret; + __ret *= 10U; } + return __ret; + } + public: - static unsigned constexpr fractional_width = __hh_mm_ss_width(__CommonType::period::den) < 19 ? - __hh_mm_ss_width(__CommonType::period::den) : 6u; - using precision = duration>; - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {} - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr explicit hh_mm_ss(_Duration __d) noexcept : - __is_neg(__d < _Duration(0)), - __h(duration_cast (abs(__d))), - __m(duration_cast(abs(__d) - hours())), - __s(duration_cast(abs(__d) - hours() - minutes())), - __f(duration_cast (abs(__d) - hours() - minutes() - seconds())) - {} - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr bool is_negative() const noexcept { return __is_neg; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::hours hours() const noexcept { return __h; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::minutes minutes() const noexcept { return __m; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::seconds seconds() const noexcept { return __s; } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr precision subseconds() const noexcept { return __f; } - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr precision to_duration() const noexcept - { - auto __dur = __h + __m + __s + __f; - return __is_neg ? -__dur : __dur; - } + static unsigned constexpr fractional_width = + __hh_mm_ss_width(__CommonType::period::den) < 19 ? __hh_mm_ss_width(__CommonType::period::den) : 6u; + using precision = duration>; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr hh_mm_ss() noexcept + : hh_mm_ss{_Duration::zero()} + {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit hh_mm_ss(_Duration __d) noexcept + : __is_neg(__d < _Duration(0)) + , __h(duration_cast(abs(__d))) + , __m(duration_cast(abs(__d) - hours())) + , __s(duration_cast(abs(__d) - hours() - minutes())) + , __f(duration_cast(abs(__d) - hours() - minutes() - seconds())) + {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool is_negative() const noexcept + { + return __is_neg; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::hours hours() const noexcept + { + return __h; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::minutes minutes() const noexcept + { + return __m; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::seconds seconds() const noexcept + { + return __s; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr precision subseconds() const noexcept + { + return __f; + } + + _LIBCUDACXX_INLINE_VISIBILITY constexpr precision to_duration() const noexcept + { + auto __dur = __h + __m + __s + __f; + return __is_neg ? -__dur : __dur; + } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr explicit operator precision() const noexcept { return to_duration(); } + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit operator precision() const noexcept + { + return to_duration(); + } private: - bool __is_neg; - chrono::hours __h; - chrono::minutes __m; - chrono::seconds __s; - precision __f; + bool __is_neg; + chrono::hours __h; + chrono::minutes __m; + chrono::seconds __s; + precision __f; }; -_LIBCUDACXX_INLINE_VISIBILITY -constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); } +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool is_am(const hours& __h) noexcept +{ + return __h >= hours(0) && __h < hours(12); +} +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool is_pm(const hours& __h) noexcept +{ + return __h >= hours(12) && __h < hours(24); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr hours make12(const hours& __h) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr hours make12(const hours& __h) noexcept { - if (__h == hours( 0)) return hours(12); - else if (__h <= hours(12)) return __h; - else return __h - hours(12); + if (__h == hours(0)) + { + return hours(12); + } + else if (__h <= hours(12)) + { + return __h; + } + else + { + return __h - hours(12); + } } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr hours make24(const hours& __h, bool __is_pm) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr hours make24(const hours& __h, bool __is_pm) noexcept { - if (__is_pm) - return __h == hours(12) ? __h : __h + hours(12); - else - return __h == hours(12) ? hours(0) : __h; + if (__is_pm) + { + return __h == hours(12) ? __h : __h + hours(12); + } + else + { + return __h == hours(12) ? hours(0) : __h; + } } #endif // _CCCL_STD_VER > 2011 -} // chrono +} // namespace chrono #if _CCCL_STD_VER > 2011 // GCC 5 and 6 warn (and then error) on us using the standard reserved UDL names, // but have no way of disabling that. Use the system_header pragma on those GCC versions // for the remainder of this file, even if it has been requested to disable the pragma // earlier. -#if defined(_CCCL_COMPILER_GCC) && (__GNUC__ == 5 || __GNUC__ == 6) -#pragma GCC system_header -#endif +# if defined(_CCCL_COMPILER_GCC) && (__GNUC__ == 5 || __GNUC__ == 6) +# pragma GCC system_header +# endif _CCCL_DIAG_PUSH _CCCL_DIAG_SUPPRESS_GCC("-Wliteral-suffix") @@ -3212,100 +3608,94 @@ _CCCL_DIAG_SUPPRESS_MSVC(4455) // Suffixes for duration literals [time.duration.literals] inline namespace literals { - inline namespace chrono_literals - { +inline namespace chrono_literals +{ - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::hours operator""h(unsigned long long __h) - { - return chrono::hours(static_cast(__h)); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::hours operator""h(unsigned long long __h) +{ + return chrono::hours(static_cast(__h)); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<3600,1>> operator""h(long double __h) - { - return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<3600,1>>(__h); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<3600, 1>> +operator""h(long double __h) +{ + return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<3600, 1>>(__h); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::minutes operator""min(unsigned long long __m) - { - return chrono::minutes(static_cast(__m)); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::minutes operator""min(unsigned long long __m) +{ + return chrono::minutes(static_cast(__m)); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<60,1>> operator""min(long double __m) - { - return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<60,1>> (__m); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<60, 1>> +operator""min(long double __m) +{ + return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, ratio<60, 1>>(__m); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::seconds operator""s(unsigned long long __s) - { - return chrono::seconds(static_cast(__s)); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::seconds operator""s(unsigned long long __s) +{ + return chrono::seconds(static_cast(__s)); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T> operator""s(long double __s) - { - return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T> (__s); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T> +operator""s(long double __s) +{ + return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T>(__s); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::milliseconds operator""ms(unsigned long long __ms) - { - return chrono::milliseconds(static_cast(__ms)); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::milliseconds operator""ms(unsigned long long __ms) +{ + return chrono::milliseconds(static_cast(__ms)); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, milli> operator""ms(long double __ms) - { - return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, milli>(__ms); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, milli> +operator""ms(long double __ms) +{ + return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, milli>(__ms); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::microseconds operator""us(unsigned long long __us) - { - return chrono::microseconds(static_cast(__us)); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::microseconds operator""us(unsigned long long __us) +{ + return chrono::microseconds(static_cast(__us)); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, micro> operator""us(long double __us) - { - return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, micro> (__us); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, micro> +operator""us(long double __us) +{ + return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, micro>(__us); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) - { - return chrono::nanoseconds(static_cast(__ns)); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) +{ + return chrono::nanoseconds(static_cast(__ns)); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, nano> operator""ns(long double __ns) - { - return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, nano> (__ns); - } +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, nano> +operator""ns(long double __ns) +{ + return chrono::duration<_LIBCUDACXX_CHRONO_LITERAL_INTERNAL_T, nano>(__ns); +} -#if _CCCL_STD_VER > 2017 && !defined(_LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS) - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::day operator""d(unsigned long long __d) noexcept - { - return chrono::day(static_cast(__d)); - } +# if _CCCL_STD_VER > 2017 && !defined(_LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS) +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::day operator""d(unsigned long long __d) noexcept +{ + return chrono::day(static_cast(__d)); +} - _LIBCUDACXX_INLINE_VISIBILITY - constexpr chrono::year operator""y(unsigned long long __y) noexcept - { - return chrono::year(static_cast(__y)); - } -#endif //_CCCL_STD_VER > 2017 && !defined(_LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS) -}} +_LIBCUDACXX_INLINE_VISIBILITY constexpr chrono::year operator""y(unsigned long long __y) noexcept +{ + return chrono::year(static_cast(__y)); +} +# endif //_CCCL_STD_VER > 2017 && !defined(_LIBCUDACXX_HAS_NO_CXX20_CHRONO_LITERALS) +} // namespace chrono_literals +} // namespace literals _CCCL_DIAG_POP -namespace chrono { // hoist the literals into namespace std::chrono - using namespace literals::chrono_literals; +namespace chrono +{ // hoist the literals into namespace std::chrono +using namespace literals::chrono_literals; } #endif // _CCCL_STD_VER > 2011 @@ -3315,34 +3705,33 @@ _LIBCUDACXX_END_NAMESPACE_STD #ifndef __cuda_std__ _LIBCUDACXX_BEGIN_NAMESPACE_FILESYSTEM -struct _FilesystemClock { -#if !defined(_LIBCUDACXX_HAS_NO_INT128) +struct _FilesystemClock +{ +# if !defined(_LIBCUDACXX_HAS_NO_INT128) typedef __int128_t rep; typedef nano period; -#else +# else typedef long long rep; typedef nano period; -#endif +# endif typedef chrono::duration duration; typedef chrono::time_point<_FilesystemClock> time_point; - _LIBCUDACXX_EXPORTED_FROM_ABI - static _CCCL_CONSTEXPR_CXX14 const bool is_steady = false; + _LIBCUDACXX_EXPORTED_FROM_ABI static _CCCL_CONSTEXPR_CXX14 const bool is_steady = false; _LIBCUDACXX_AVAILABILITY_FILESYSTEM _LIBCUDACXX_FUNC_VIS static time_point now() noexcept; - _LIBCUDACXX_INLINE_VISIBILITY - static time_t to_time_t(const time_point& __t) noexcept { - typedef chrono::duration __secs; - return time_t( - chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); + _LIBCUDACXX_INLINE_VISIBILITY static time_t to_time_t(const time_point& __t) noexcept + { + typedef chrono::duration __secs; + return time_t(chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); } - _LIBCUDACXX_INLINE_VISIBILITY - static time_point from_time_t(time_t __t) noexcept { - typedef chrono::duration __secs; - return time_point(__secs(__t)); + _LIBCUDACXX_INLINE_VISIBILITY static time_point from_time_t(time_t __t) noexcept + { + typedef chrono::duration __secs; + return time_point(__secs(__t)); } }; _LIBCUDACXX_END_NAMESPACE_FILESYSTEM @@ -3353,4 +3742,4 @@ _CCCL_NV_DIAG_DEFAULT(cuda_demote_unsupported_floating_point) #include #include -#endif // _LIBCUDACXX_CHRONO +#endif // _LIBCUDACXX_CHRONO diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/climits b/libcudacxx/include/cuda/std/detail/libcxx/include/climits index 330c54a02d4..0b80d0b8b32 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/climits +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/climits @@ -48,24 +48,25 @@ Macros: #endif // no system header #include + #include #if defined(_CCCL_COMPILER_MSVC) -#include +# include #endif // _LIBCUDACXX_MSVCRT #if defined(_CCCL_COMPILER_IBM) -#include +# include #endif // _CCCL_COMPILER_IBM // ICC defines __CHAR_BIT__ by default // accept that, but assert it is what we expect #ifdef __CHAR_BIT__ - static_assert(__CHAR_BIT__ == 8, ""); +static_assert(__CHAR_BIT__ == 8, ""); #else - #define __CHAR_BIT__ 8 +# define __CHAR_BIT__ 8 #endif #include -#endif // _LIBCUDACXX_CLIMITS +#endif // _LIBCUDACXX_CLIMITS diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cmath b/libcudacxx/include/cuda/std/detail/libcxx/include/cmath index 4ef9fbcc74b..d2744a9c415 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cmath +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cmath @@ -311,11 +311,11 @@ long double truncl(long double x); #endif // no system header #if !defined(_CCCL_COMPILER_NVRTC) || !defined(__cuda_std__) -#include +# include #endif #if defined(__cuda_std__) && defined(_CCCL_COMPILER_NVHPC) -#include +# include #endif #include @@ -323,36 +323,36 @@ long double truncl(long double x); #include #ifdef _LIBCUDACXX_HAS_NVFP16 -#include +# include #endif // _LIBCUDACXX_HAS_NVFP16 #ifdef _LIBCUDACXX_HAS_NVBF16 -#include +# include #endif // _LIBCUDACXX_HAS_NVBF16 -#include - #ifdef _CCCL_COMPILER_NVRTC -#include -#define INFINITY __builtin_huge_val() -#define NAN __builtin_nan() +# include +# define INFINITY __builtin_huge_val() +# define NAN __builtin_nan() #endif // _CCCL_COMPILER_NVRTC +#include + _LIBCUDACXX_BEGIN_NAMESPACE_STD -using ::signbit; using ::isfinite; using ::isinf; using ::isnan; +using ::signbit; using ::acos; using ::acosf; using ::asin; using ::asinf; using ::atan; -using ::atanf; using ::atan2; using ::atan2f; +using ::atanf; using ::ceil; using ::ceilf; using ::cos; @@ -399,17 +399,17 @@ using ::abs; #ifndef _CCCL_COMPILER_NVRTC using ::fpclassify; -using ::isnormal; using ::isgreater; using ::isgreaterequal; using ::isless; using ::islessequal; using ::islessgreater; +using ::isnormal; using ::isunordered; -using ::float_t; using ::double_t; +using ::float_t; using ::fabs; using ::fabsf; @@ -461,17 +461,17 @@ using ::copysign; using ::copysignf; using ::erf; -using ::erff; using ::erfc; using ::erfcf; +using ::erff; using ::exp2; using ::exp2f; using ::expm1; using ::expm1f; using ::fdim; using ::fdimf; -using ::fmaf; using ::fma; +using ::fmaf; using ::fmax; using ::fmaxf; using ::fmin; @@ -523,36 +523,36 @@ using ::truncf; using ::acosl; using ::asinl; -using ::atanl; using ::atan2l; +using ::atanl; using ::ceill; -using ::cosl; using ::coshl; +using ::cosl; using ::expl; using ::fabsl; using ::floorl; using ::fmodl; using ::frexpl; using ::ldexpl; -using ::logl; using ::log10l; +using ::logl; using ::modfl; using ::powl; -using ::sinl; using ::sinhl; +using ::sinl; using ::sqrtl; using ::tanl; -using ::tanhl; using ::acoshl; using ::asinhl; using ::atanhl; using ::cbrtl; +using ::tanhl; using ::copysignl; -using ::erfl; using ::erfcl; +using ::erfl; using ::exp2l; using ::expm1l; using ::fdiml; @@ -585,224 +585,244 @@ using ::truncl; #endif // _CCCL_COMPILER_NVRTC #if _CCCL_STD_VER > 2014 && !defined(__cuda_std__) -inline _LIBCUDACXX_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } -inline _LIBCUDACXX_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } -#ifdef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE -inline _LIBCUDACXX_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } -#endif +inline _LIBCUDACXX_INLINE_VISIBILITY float hypot(float x, float y, float z) +{ + return sqrt(x * x + y * y + z * z); +} +inline _LIBCUDACXX_INLINE_VISIBILITY double hypot(double x, double y, double z) +{ + return sqrt(x * x + y * y + z * z); +} +# ifdef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE +inline _LIBCUDACXX_INLINE_VISIBILITY long double hypot(long double x, long double y, long double z) +{ + return sqrt(x * x + y * y + z * z); +} +# endif template inline _LIBCUDACXX_INLINE_VISIBILITY -__enable_if_t -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value && - is_arithmetic<_A3>::value, - __promote<_A1, _A2, _A3> -> -hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) noexcept -{ - using __result_type = __promote_t<_A1, _A2, _A3>; - static_assert((!(is_same<_A1, __result_type>::value && - is_same<_A2, __result_type>::value && - is_same<_A3, __result_type>::value)), ""); - return ::hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); + __enable_if_t::value && is_arithmetic<_A2>::value && is_arithmetic<_A3>::value, + __promote<_A1, _A2, _A3>> + hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) noexcept +{ + using __result_type = __promote_t<_A1, _A2, _A3>; + static_assert( + (!(is_same<_A1, __result_type>::value && is_same<_A2, __result_type>::value && is_same<_A3, __result_type>::value)), + ""); + return ::hypot((__result_type) __lcpp_x, (__result_type) __lcpp_y, (__result_type) __lcpp_z); } #endif #ifndef _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS -#define _CCCL_CONSTEXPR_CXX14_COMPLEX _CCCL_CONSTEXPR_CXX14 +# define _CCCL_CONSTEXPR_CXX14_COMPLEX _CCCL_CONSTEXPR_CXX14 #else -#define _CCCL_CONSTEXPR_CXX14_COMPLEX +# define _CCCL_CONSTEXPR_CXX14_COMPLEX #endif // _LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS template -_LIBCUDACXX_INLINE_VISIBILITY -constexpr __enable_if_t::value, bool> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t::value, bool> __constexpr_isnan(_A1 __lcpp_x) noexcept { #if defined(_CCCL_CUDACC_BELOW_11_8) - return __isnan(__lcpp_x); + return __isnan(__lcpp_x); #elif __has_builtin(__builtin_isnan) - // nvcc at times has issues determining the type of __lcpp_x - return __builtin_isnan(static_cast(__lcpp_x)); + // nvcc at times has issues determining the type of __lcpp_x + return __builtin_isnan(static_cast(__lcpp_x)); #else - return ::isnan(__lcpp_x); + return ::isnan(__lcpp_x); #endif } template -_LIBCUDACXX_INLINE_VISIBILITY -constexpr __enable_if_t::value, bool> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t::value, bool> __constexpr_isnan(_A1 __lcpp_x) noexcept { - return ::isnan(__lcpp_x); + return ::isnan(__lcpp_x); } template -_LIBCUDACXX_INLINE_VISIBILITY -constexpr __enable_if_t::value, bool> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t::value, bool> __constexpr_isinf(_A1 __lcpp_x) noexcept { #if defined(_CCCL_CUDACC_BELOW_11_8) - return __isinf(__lcpp_x); + return __isinf(__lcpp_x); #elif __has_builtin(__builtin_isinf) - // nvcc at times has issues determining the type of __lcpp_x - return __builtin_isinf(static_cast(__lcpp_x)); + // nvcc at times has issues determining the type of __lcpp_x + return __builtin_isinf(static_cast(__lcpp_x)); #else - return ::isinf(__lcpp_x); + return ::isinf(__lcpp_x); #endif } template -_LIBCUDACXX_INLINE_VISIBILITY -constexpr __enable_if_t::value, bool> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t::value, bool> __constexpr_isinf(_A1 __lcpp_x) noexcept { - return ::isinf(__lcpp_x); + return ::isinf(__lcpp_x); } template -_LIBCUDACXX_INLINE_VISIBILITY -constexpr __enable_if_t::value, bool> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t::value, bool> __constexpr_isfinite(_A1 __lcpp_x) noexcept { #if defined(_CCCL_CUDACC_BELOW_11_8) - return !__isinf(__lcpp_x) && !__isnan(__lcpp_x); + return !__isinf(__lcpp_x) && !__isnan(__lcpp_x); #elif __has_builtin(__builtin_isfinite) - // nvcc at times has issues determining the type of __lcpp_x - return __builtin_isfinite(static_cast(__lcpp_x)); + // nvcc at times has issues determining the type of __lcpp_x + return __builtin_isfinite(static_cast(__lcpp_x)); #else - return ::isfinite(__lcpp_x); + return ::isfinite(__lcpp_x); #endif } template -_LIBCUDACXX_INLINE_VISIBILITY -constexpr __enable_if_t::value, bool> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t::value, bool> __constexpr_isfinite(_A1 __lcpp_x) noexcept { - return isfinite(__lcpp_x); + return isfinite(__lcpp_x); } #if defined(_CCCL_COMPILER_MSVC) || defined(_CCCL_COMPILER_NVRTC) template -_LIBCUDACXX_INLINE_VISIBILITY -_A1 __constexpr_copysign(_A1 __x, _A1 __y) noexcept +_LIBCUDACXX_INLINE_VISIBILITY _A1 __constexpr_copysign(_A1 __x, _A1 __y) noexcept { - return ::copysign(__x, __y); + return ::copysign(__x, __y); } #else -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 float __constexpr_copysign(float __x, float __y) noexcept { - return __builtin_copysignf(__x, __y); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 float +__constexpr_copysign(float __x, float __y) noexcept +{ + return __builtin_copysignf(__x, __y); } -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 double __constexpr_copysign(double __x, double __y) noexcept { - return __builtin_copysign(__x, __y); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 double +__constexpr_copysign(double __x, double __y) noexcept +{ + return __builtin_copysign(__x, __y); } -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 long double __constexpr_copysign(long double __x, long double __y) noexcept { - return __builtin_copysignl(__x, __y); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 long double +__constexpr_copysign(long double __x, long double __y) noexcept +{ + return __builtin_copysignl(__x, __y); } template -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 __enable_if_t::value && is_arithmetic<_A2>::value, - __promote_t<_A1, _A2>> - __constexpr_copysign(_A1 __x, _A2 __y) noexcept { - using __result_type = __promote_t<_A1, _A2>; - static_assert((!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value)), ""); - return __builtin_copysign((__result_type)__x, (__result_type)__y); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 + __enable_if_t::value && is_arithmetic<_A2>::value, __promote_t<_A1, _A2>> + __constexpr_copysign(_A1 __x, _A2 __y) noexcept +{ + using __result_type = __promote_t<_A1, _A2>; + static_assert((!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value)), ""); + return __builtin_copysign((__result_type) __x, (__result_type) __y); } #endif // !_CCCL_COMPILER_MSVC #if defined(_CCCL_COMPILER_MSVC) || defined(_CCCL_COMPILER_NVRTC) template -_LIBCUDACXX_INLINE_VISIBILITY -_A1 __constexpr_fabs(_A1 __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY _A1 __constexpr_fabs(_A1 __x) noexcept { - return ::fabs(__x); + return ::fabs(__x); } #else -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 float __constexpr_fabs(float __x) noexcept { - return __builtin_fabsf(__x); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 float +__constexpr_fabs(float __x) noexcept +{ + return __builtin_fabsf(__x); } -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 double __constexpr_fabs(double __x) noexcept { - return __builtin_fabs(__x); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 double +__constexpr_fabs(double __x) noexcept +{ + return __builtin_fabs(__x); } -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 long double __constexpr_fabs(long double __x) noexcept { - return __builtin_fabsl(__x); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 long double +__constexpr_fabs(long double __x) noexcept +{ + return __builtin_fabsl(__x); } template ::value, int> = 0> -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14 double __constexpr_fabs(_Tp __x) noexcept { - return __builtin_fabs(static_cast(__x)); +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 double +__constexpr_fabs(_Tp __x) noexcept +{ + return __builtin_fabs(static_cast(__x)); } #endif // !_CCCL_COMPILER_MSVC #if defined(_CCCL_COMPILER_MSVC) || defined(_CCCL_COMPILER_NVRTC) template -_LIBCUDACXX_INLINE_VISIBILITY -_A1 __constexpr_fmax(_A1 __x, _A1 __y) noexcept +_LIBCUDACXX_INLINE_VISIBILITY _A1 __constexpr_fmax(_A1 __x, _A1 __y) noexcept { - return ::fmax(__x, __y); + return ::fmax(__x, __y); } #else -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14_COMPLEX float __constexpr_fmax(float __x, float __y) noexcept { -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) - if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) { +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX float +__constexpr_fmax(float __x, float __y) noexcept +{ +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) + if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) + { if (__constexpr_isnan(__x)) + { return __y; + } if (__constexpr_isnan(__y)) + { return __x; + } return __x < __y ? __y : __x; } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) return __builtin_fmaxf(__x, __y); } -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14_COMPLEX double __constexpr_fmax(double __x, double __y) noexcept { -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) - if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) { +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX double +__constexpr_fmax(double __x, double __y) noexcept +{ +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) + if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) + { if (__constexpr_isnan(__x)) + { return __y; + } if (__constexpr_isnan(__y)) + { return __x; + } return __x < __y ? __y : __x; } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) return __builtin_fmax(__x, __y); } -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14_COMPLEX long double __constexpr_fmax(long double __x, long double __y) noexcept { -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) - if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) { +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX long double +__constexpr_fmax(long double __x, long double __y) noexcept +{ +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) + if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) + { if (__constexpr_isnan(__x)) + { return __y; + } if (__constexpr_isnan(__y)) + { return __x; + } return __x < __y ? __y : __x; } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) return __builtin_fmax(__x, __y); } template ::value && is_arithmetic<_Up>::value, int> = 0> -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14_COMPLEX __promote_t<_Tp, _Up> -__constexpr_fmax(_Tp __x, _Up __y) noexcept { +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX __promote_t<_Tp, _Up> +__constexpr_fmax(_Tp __x, _Up __y) noexcept +{ using __result_type = __promote_t<_Tp, _Up>; return _CUDA_VSTD::__constexpr_fmax(static_cast<__result_type>(__x), static_cast<__result_type>(__y)); } @@ -810,156 +830,193 @@ __constexpr_fmax(_Tp __x, _Up __y) noexcept { #if defined(_CCCL_COMPILER_MSVC) || defined(_CCCL_COMPILER_NVRTC) || defined(_CCCL_CUDA_COMPILER_CLANG) template -_LIBCUDACXX_INLINE_VISIBILITY -_A1 __constexpr_logb(_A1 __x) +_LIBCUDACXX_INLINE_VISIBILITY _A1 __constexpr_logb(_A1 __x) { - return ::logb(__x); + return ::logb(__x); } #else template -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14_COMPLEX _Tp __constexpr_logb(_Tp __x) { -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) - if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) { - if (__x == _Tp(0)) { +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX _Tp +__constexpr_logb(_Tp __x) +{ +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) + if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) + { + if (__x == _Tp(0)) + { // raise FE_DIVBYZERO return -numeric_limits<_Tp>::infinity(); } if (__constexpr_isinf(__x)) + { return numeric_limits<_Tp>::infinity(); + } if (__constexpr_isnan(__x)) + { return numeric_limits<_Tp>::quiet_NaN(); + } - __x = __constexpr_fabs(__x); + __x = __constexpr_fabs(__x); unsigned long long __exp = 0; - while (__x >= _Tp(numeric_limits<_Tp>::radix)) { + while (__x >= _Tp(numeric_limits<_Tp>::radix)) + { __x /= numeric_limits<_Tp>::radix; __exp += 1; } return _Tp(__exp); } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) return __builtin_logb(__x); } #endif // !_MSVC #if defined(_CCCL_COMPILER_MSVC) || defined(_CCCL_COMPILER_NVRTC) || defined(_CCCL_CUDA_COMPILER_CLANG) template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp __constexpr_scalbn(_Tp __x, int __i) { - return static_cast<_Tp>(::scalbn(static_cast(__x), __i)); +inline _LIBCUDACXX_INLINE_VISIBILITY _Tp __constexpr_scalbn(_Tp __x, int __i) +{ + return static_cast<_Tp>(::scalbn(static_cast(__x), __i)); } template <> -inline _LIBCUDACXX_INLINE_VISIBILITY -float __constexpr_scalbn(float __x, int __i) { - return ::scalbnf(__x, __i); +inline _LIBCUDACXX_INLINE_VISIBILITY float __constexpr_scalbn(float __x, int __i) +{ + return ::scalbnf(__x, __i); } template <> -inline _LIBCUDACXX_INLINE_VISIBILITY -double __constexpr_scalbn(double __x, int __i) { - return ::scalbn(__x, __i); +inline _LIBCUDACXX_INLINE_VISIBILITY double __constexpr_scalbn(double __x, int __i) +{ + return ::scalbn(__x, __i); } -#ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE +# ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE template <> -inline _LIBCUDACXX_INLINE_VISIBILITY -long double __constexpr_scalbn(long double __x, int __i) { - return ::scalbnl(__x, __i); +inline _LIBCUDACXX_INLINE_VISIBILITY long double __constexpr_scalbn(long double __x, int __i) +{ + return ::scalbnl(__x, __i); } -#endif // _LIBCUDACXX_HAS_NO_LONG_DOUBLE +# endif // _LIBCUDACXX_HAS_NO_LONG_DOUBLE #else template -inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY -_CCCL_CONSTEXPR_CXX14_COMPLEX _Tp __constexpr_scalbn(_Tp __x, int __exp) { -#if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) - if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) { +inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX _Tp +__constexpr_scalbn(_Tp __x, int __exp) +{ +# if defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) && !defined(_LIBCUDACXX_HAS_NO_CONSTEXPR_COMPLEX_OPERATIONS) + if (_LIBCUDACXX_IS_CONSTANT_EVALUATED()) + { if (__x == _Tp(0)) + { return __x; + } if (__constexpr_isinf(__x)) + { return __x; + } if (_Tp(__exp) == _Tp(0)) + { return __x; + } if (__constexpr_isnan(__x)) + { return numeric_limits<_Tp>::quiet_NaN(); + } _Tp __mult(1); - if (__exp > 0) { + if (__exp > 0) + { __mult = numeric_limits<_Tp>::radix; --__exp; - } else { + } + else + { ++__exp; __exp = -__exp; __mult /= numeric_limits<_Tp>::radix; } - while (__exp > 0) { - if (!(__exp & 1)) { + while (__exp > 0) + { + if (!(__exp & 1)) + { __mult *= __mult; __exp >>= 1; - } else { + } + else + { __x *= __mult; --__exp; } } return __x; } -#endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) +# endif // defined(_LIBCUDACXX_IS_CONSTANT_EVALUATED) return __builtin_scalbn(__x, __exp); } #endif // !_CCCL_COMPILER_MSVC #if _CCCL_STD_VER > 2017 template -_LIBCUDACXX_INLINE_VISIBILITY -constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept { - if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0)) - return __t * __b + (1 - __t) * __a; - - if (__t == 1) return __b; - const _Fp __x = __a + __t * (__b - __a); - if (__t > 1 == __b > __a) - return __b < __x ? __x : __b; - else - return __x < __b ? __x : __b; +_LIBCUDACXX_INLINE_VISIBILITY constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept +{ + if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0)) + { + return __t * __b + (1 - __t) * __a; + } + + if (__t == 1) + { + return __b; + } + const _Fp __x = __a + __t * (__b - __a); + if (__t > 1 == __b > __a) + { + return __b < __x ? __x : __b; + } + else + { + return __x < __b ? __x : __b; + } } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr float -lerp(float __a, float __b, float __t) noexcept { return __lerp(__a, __b, __t); } +_LIBCUDACXX_INLINE_VISIBILITY constexpr float lerp(float __a, float __b, float __t) noexcept +{ + return __lerp(__a, __b, __t); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr double -lerp(double __a, double __b, double __t) noexcept { return __lerp(__a, __b, __t); } +_LIBCUDACXX_INLINE_VISIBILITY constexpr double lerp(double __a, double __b, double __t) noexcept +{ + return __lerp(__a, __b, __t); +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr long double -lerp(long double __a, long double __b, long double __t) noexcept { return __lerp(__a, __b, __t); } +_LIBCUDACXX_INLINE_VISIBILITY constexpr long double lerp(long double __a, long double __b, long double __t) noexcept +{ + return __lerp(__a, __b, __t); +} #endif // _CCCL_STD_VER > 2017 -template ::digits > numeric_limits<_IntT>::digits), - int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)> -_LIBCUDACXX_INLINE_VISIBILITY -constexpr _IntT __max_representable_int_for_float() noexcept { +template ::digits > numeric_limits<_IntT>::digits), + int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)> +_LIBCUDACXX_INLINE_VISIBILITY constexpr _IntT __max_representable_int_for_float() noexcept +{ static_assert(is_floating_point<_FloatT>::value, "must be a floating point type"); static_assert(is_integral<_IntT>::value, "must be an integral type"); static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix"); #ifdef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE - static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value - || _IsSame<_FloatT,long double>::value), "unsupported floating point type"); + static_assert( + (_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value || _IsSame<_FloatT, long double>::value), + "unsupported floating point type"); #else - static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value), - "unsupported floating point type"); + static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value), "unsupported floating point type"); #endif - return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits); + return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits); } // Convert a floating point number to the specified integral type after @@ -967,13 +1024,16 @@ constexpr _IntT __max_representable_int_for_float() noexcept { // // The behavior is undefined if `__r` is NaN. template -_LIBCUDACXX_INLINE_VISIBILITY -_IntT __clamp_to_integral(_RealT __r) noexcept { - using _Lim = _CUDA_VSTD::numeric_limits<_IntT>; +_LIBCUDACXX_INLINE_VISIBILITY _IntT __clamp_to_integral(_RealT __r) noexcept +{ + using _Lim = _CUDA_VSTD::numeric_limits<_IntT>; const _IntT _MaxVal = _CUDA_VSTD::__max_representable_int_for_float<_IntT, _RealT>(); - if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) { + if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) + { return _Lim::max(); - } else if (__r <= _Lim::lowest()) { + } + else if (__r <= _Lim::lowest()) + { return _Lim::min(); } return static_cast<_IntT>(__r); @@ -983,4 +1043,4 @@ _LIBCUDACXX_END_NAMESPACE_STD #include -#endif // _LIBCUDACXX_CMATH +#endif // _LIBCUDACXX_CMATH diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/complex b/libcudacxx/include/cuda/std/detail/libcxx/include/complex index bd6b167ca90..a6fb816477b 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/complex +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/complex @@ -242,7 +242,6 @@ template complex tanh (const complex&); # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include @@ -250,10 +249,11 @@ template complex tanh (const complex&); #include #include #include -#include #include #include #include +#include // all public C++ headers provide the assertion handler +#include #include #include @@ -424,13 +424,15 @@ public: }; template -_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX complex<_Tp>& operator*=(complex<_Tp>& __lhs, const complex<_Up>& __rhs) +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX complex<_Tp>& +operator*=(complex<_Tp>& __lhs, const complex<_Up>& __rhs) { __lhs = __lhs * complex<_Tp>(__rhs.real(), __rhs.imag()); return __lhs; } template -_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX complex<_Tp>& operator/=(complex<_Tp>& __lhs, const complex<_Up>& __rhs) +_LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14_COMPLEX complex<_Tp>& +operator/=(complex<_Tp>& __lhs, const complex<_Up>& __rhs) { __lhs = __lhs / complex<_Tp>(__rhs.real(), __rhs.imag()); return __lhs; @@ -840,7 +842,7 @@ inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Tp real(const comple // 26.3.7 values: -template +template struct __libcpp_complex_overload_traits {}; @@ -904,14 +906,14 @@ inline _LIBCUDACXX_INLINE_VISIBILITY _Tp arg(const complex<_Tp>& __c) #ifdef _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE template -inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t< is_same<_Tp, long double>::value, long double > arg(_Tp __re) +inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t::value, long double> arg(_Tp __re) { return _CUDA_VSTD::atan2l(0.L, __re); } #endif // _LIBCUDACXX_HAS_COMPLEX_LONG_DOUBLE template -inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t< is_integral<_Tp>::value || is_same<_Tp, double>::value, double > +inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t::value || is_same<_Tp, double>::value, double> arg(_Tp __re) { // integrals need to be promoted to double @@ -919,7 +921,7 @@ arg(_Tp __re) } template -inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t< is_same<_Tp, float>::value, float > arg(_Tp __re) +inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t::value, float> arg(_Tp __re) { return _CUDA_VSTD::atan2f(0.F, __re); } @@ -1115,7 +1117,7 @@ inline _LIBCUDACXX_INLINE_VISIBILITY complex<__promote_t<_Tp, _Up>> pow(const co } template -inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t< __is_complex_arithmetic<_Up>::value, complex<__promote_t<_Tp, _Up>> > +inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t<__is_complex_arithmetic<_Up>::value, complex<__promote_t<_Tp, _Up>>> pow(const complex<_Tp>& __x, const _Up& __y) { using __result_type = complex<__promote_t<_Tp, _Up>>; @@ -1123,7 +1125,7 @@ pow(const complex<_Tp>& __x, const _Up& __y) } template -inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t< __is_complex_arithmetic<_Tp>::value, complex<__promote_t<_Tp, _Up>> > +inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t<__is_complex_arithmetic<_Tp>::value, complex<__promote_t<_Tp, _Up>>> pow(const _Tp& __x, const complex<_Up>& __y) { using __result_type = complex<__promote_t<_Tp, _Up>>; diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cstddef b/libcudacxx/include/cuda/std/detail/libcxx/include/cstddef index c4de4ba13b1..3ee664b52ea 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cstddef +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cstddef @@ -43,10 +43,10 @@ Types: # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include +#include // all public C++ headers provide the assertion handler #include #include @@ -56,8 +56,8 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD using ::ptrdiff_t; using ::size_t; -#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \ - defined(__DEFINED_max_align_t) || defined(__NetBSD__) +#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || defined(__DEFINED_max_align_t) \ + || defined(__NetBSD__) // Re-use the compiler's max_align_t where possible. using ::max_align_t; #else @@ -67,98 +67,95 @@ typedef long double max_align_t; _LIBCUDACXX_END_NAMESPACE_STD #if _CCCL_STD_VER > 2011 -#ifdef _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION +# ifdef _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION _LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION -#else -namespace std // purposefully not versioned +# else +namespace std // purposefully not versioned { -#endif //_LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION -enum class byte : unsigned char {}; +# endif //_LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION +enum class byte : unsigned char +{ +}; -_LIBCUDACXX_INLINE_VISIBILITY -constexpr byte operator| (byte __lhs, byte __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr byte operator|(byte __lhs, byte __rhs) noexcept { - return static_cast( - static_cast( - static_cast(__lhs) | static_cast(__rhs) - )); + return static_cast( + static_cast(static_cast(__lhs) | static_cast(__rhs))); } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = __lhs | __rhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept +{ + return __lhs = __lhs | __rhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr byte operator& (byte __lhs, byte __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr byte operator&(byte __lhs, byte __rhs) noexcept { - return static_cast( - static_cast( - static_cast(__lhs) & static_cast(__rhs) - )); + return static_cast( + static_cast(static_cast(__lhs) & static_cast(__rhs))); } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = __lhs & __rhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept +{ + return __lhs = __lhs & __rhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr byte operator^ (byte __lhs, byte __rhs) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr byte operator^(byte __lhs, byte __rhs) noexcept { - return static_cast( - static_cast( - static_cast(__lhs) ^ static_cast(__rhs) - )); + return static_cast( + static_cast(static_cast(__lhs) ^ static_cast(__rhs))); } -_LIBCUDACXX_INLINE_VISIBILITY -constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = __lhs ^ __rhs; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept +{ + return __lhs = __lhs ^ __rhs; +} -_LIBCUDACXX_INLINE_VISIBILITY -constexpr byte operator~ (byte __b) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr byte operator~(byte __b) noexcept { - return static_cast( - static_cast( - ~static_cast(__b) - )); + return static_cast(static_cast(~static_cast(__b))); } template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> & - operator<<=(byte& __lhs, _Integer __shift) noexcept - { return __lhs = __lhs << __shift; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t, byte>& +operator<<=(byte& __lhs, _Integer __shift) noexcept +{ + return __lhs = __lhs << __shift; +} template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> - operator<< (byte __lhs, _Integer __shift) noexcept - { return static_cast(static_cast(static_cast(__lhs) << __shift)); } +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t, byte> +operator<<(byte __lhs, _Integer __shift) noexcept +{ + return static_cast(static_cast(static_cast(__lhs) << __shift)); +} template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> & - operator>>=(byte& __lhs, _Integer __shift) noexcept - { return __lhs = __lhs >> __shift; } +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t, byte>& +operator>>=(byte& __lhs, _Integer __shift) noexcept +{ + return __lhs = __lhs >> __shift; +} template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, byte> - operator>> (byte __lhs, _Integer __shift) noexcept - { return static_cast(static_cast(static_cast(__lhs) >> __shift)); } +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t, byte> +operator>>(byte __lhs, _Integer __shift) noexcept +{ + return static_cast(static_cast(static_cast(__lhs) >> __shift)); +} template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __enable_if_t, _Integer> - to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t, _Integer> to_integer(byte __b) noexcept +{ + return static_cast<_Integer>(__b); +} -#ifdef _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION +# ifdef _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION _LIBCUDACXX_END_NAMESPACE_STD_NOVERSION -#else +# else } -#endif //_LIBCUDACXX_END_NAMESPACE_STD_NOVERSION +# endif //_LIBCUDACXX_END_NAMESPACE_STD_NOVERSION #endif // _CCCL_STD_VER > 2011 #include //__cuda_std__ -#endif // _LIBCUDACXX_CSTDDEF +#endif // _LIBCUDACXX_CSTDDEF diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cstdint b/libcudacxx/include/cuda/std/detail/libcxx/include/cstdint index b403ce5646b..4e42cac7d34 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cstdint +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cstdint @@ -155,51 +155,51 @@ Types: #include #ifndef _CCCL_COMPILER_NVRTC -#include +# include #endif // _CCCL_COMPILER_NVRTC #include _LIBCUDACXX_BEGIN_NAMESPACE_STD -using::int8_t; -using::int16_t; -using::int32_t; -using::int64_t; +using ::int16_t; +using ::int32_t; +using ::int64_t; +using ::int8_t; -using::uint8_t; -using::uint16_t; -using::uint32_t; -using::uint64_t; +using ::uint16_t; +using ::uint32_t; +using ::uint64_t; +using ::uint8_t; -using::int_least8_t; -using::int_least16_t; -using::int_least32_t; -using::int_least64_t; +using ::int_least16_t; +using ::int_least32_t; +using ::int_least64_t; +using ::int_least8_t; -using::uint_least8_t; -using::uint_least16_t; -using::uint_least32_t; -using::uint_least64_t; +using ::uint_least16_t; +using ::uint_least32_t; +using ::uint_least64_t; +using ::uint_least8_t; -using::int_fast8_t; -using::int_fast16_t; -using::int_fast32_t; -using::int_fast64_t; +using ::int_fast16_t; +using ::int_fast32_t; +using ::int_fast64_t; +using ::int_fast8_t; -using::uint_fast8_t; -using::uint_fast16_t; -using::uint_fast32_t; -using::uint_fast64_t; +using ::uint_fast16_t; +using ::uint_fast32_t; +using ::uint_fast64_t; +using ::uint_fast8_t; -using::intptr_t; -using::uintptr_t; +using ::intptr_t; +using ::uintptr_t; -using::intmax_t; -using::uintmax_t; +using ::intmax_t; +using ::uintmax_t; _LIBCUDACXX_END_NAMESPACE_STD #include -#endif // _LIBCUDACXX_CSTDINT +#endif // _LIBCUDACXX_CSTDINT diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cstdlib b/libcudacxx/include/cuda/std/detail/libcxx/include/cstdlib index 8490fe0900d..8403b33e699 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cstdlib +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cstdlib @@ -92,7 +92,7 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #endif // no system header #ifndef _CCCL_COMPILER_NVRTC -# include +# include #endif // !_CCCL_COMPILER_NVRTC #include @@ -100,101 +100,104 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #if defined(_CCCL_CUDA_COMPILER_CLANG) # define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() #elif defined(__CUDA_ARCH__) -#if defined(_CCCL_CUDACC_BELOW_11_2) -# define _LIBCUDACXX_UNREACHABLE() __trap() -#elif defined(_CCCL_CUDACC_BELOW_11_3) -# define _LIBCUDACXX_UNREACHABLE() __builtin_assume(false) -#else -# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() -#endif // CUDACC above 11.4 +# if defined(_CCCL_CUDACC_BELOW_11_2) +# define _LIBCUDACXX_UNREACHABLE() __trap() +# elif defined(_CCCL_CUDACC_BELOW_11_3) +# define _LIBCUDACXX_UNREACHABLE() __builtin_assume(false) +# else +# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() +# endif // CUDACC above 11.4 #else // ^^^ __CUDA_ARCH__ ^^^ / vvv !__CUDA_ARCH__ vvv -#if defined(_CCCL_COMPILER_MSVC_2017) -template -_LIBCUDACXX_INLINE_VISIBILITY __declspec(noreturn) void __unreachable_fallback() { __assume(0); } -# define _LIBCUDACXX_UNREACHABLE() __unreachable_fallback() -#elif defined(_CCCL_COMPILER_MSVC) -# define _LIBCUDACXX_UNREACHABLE() __assume(0) -#elif defined(_CCCL_COMPILER_GCC) || __has_builtin(__builtin_unreachable) -# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() -#else // Other compilers -# define _LIBCUDACXX_UNREACHABLE() ::abort() -#endif // Other compilers +# if defined(_CCCL_COMPILER_MSVC_2017) +template +_LIBCUDACXX_INLINE_VISIBILITY __declspec(noreturn) void __unreachable_fallback() +{ + __assume(0); +} +# define _LIBCUDACXX_UNREACHABLE() __unreachable_fallback() +# elif defined(_CCCL_COMPILER_MSVC) +# define _LIBCUDACXX_UNREACHABLE() __assume(0) +# elif defined(_CCCL_COMPILER_GCC) || __has_builtin(__builtin_unreachable) +# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() +# else // Other compilers +# define _LIBCUDACXX_UNREACHABLE() ::abort() +# endif // Other compilers #endif // !__CUDA_ARCH__ #ifdef _CCCL_COMPILER_NVHPC -#define _LIBCUDACXX_UNREACHABLE_AFTER_SWITCH() +# define _LIBCUDACXX_UNREACHABLE_AFTER_SWITCH() #else -#define _LIBCUDACXX_UNREACHABLE_AFTER_SWITCH() _LIBCUDACXX_UNREACHABLE() +# define _LIBCUDACXX_UNREACHABLE_AFTER_SWITCH() _LIBCUDACXX_UNREACHABLE() #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD #if !defined(_CCCL_COMPILER_NVRTC) -using ::size_t; using ::div_t; using ::ldiv_t; -#ifndef _LIBCUDACXX_HAS_NO_LONG_LONG +using ::size_t; +# ifndef _LIBCUDACXX_HAS_NO_LONG_LONG using ::lldiv_t; -#endif // _LIBCUDACXX_HAS_NO_LONG_LONG +# endif // _LIBCUDACXX_HAS_NO_LONG_LONG using ::atof; using ::atoi; using ::atol; -#ifndef _LIBCUDACXX_HAS_NO_LONG_LONG +# ifndef _LIBCUDACXX_HAS_NO_LONG_LONG using ::atoll; -#endif // _LIBCUDACXX_HAS_NO_LONG_LONG +# endif // _LIBCUDACXX_HAS_NO_LONG_LONG using ::strtod; using ::strtof; -using ::strtold; using ::strtol; -#ifndef _LIBCUDACXX_HAS_NO_LONG_LONG +using ::strtold; +# ifndef _LIBCUDACXX_HAS_NO_LONG_LONG using ::strtoll; -#endif // _LIBCUDACXX_HAS_NO_LONG_LONG +# endif // _LIBCUDACXX_HAS_NO_LONG_LONG using ::strtoul; -#ifndef _LIBCUDACXX_HAS_NO_LONG_LONG +# ifndef _LIBCUDACXX_HAS_NO_LONG_LONG using ::strtoull; -#endif // _LIBCUDACXX_HAS_NO_LONG_LONG -using ::rand; -using ::srand; +# endif // _LIBCUDACXX_HAS_NO_LONG_LONG +using ::_Exit; +using ::abort; +using ::atexit; using ::calloc; +using ::exit; using ::free; using ::malloc; +using ::rand; using ::realloc; -using ::abort; -using ::atexit; -using ::exit; -using ::_Exit; -#ifndef _LIBCUDACXX_WINDOWS_STORE_APP +using ::srand; +# ifndef _LIBCUDACXX_WINDOWS_STORE_APP using ::getenv; using ::system; -#endif -using ::bsearch; -using ::qsort; +# endif using ::abs; +using ::bsearch; using ::labs; -#ifndef _LIBCUDACXX_HAS_NO_LONG_LONG +using ::qsort; +# ifndef _LIBCUDACXX_HAS_NO_LONG_LONG using ::llabs; -#endif // _LIBCUDACXX_HAS_NO_LONG_LONG +# endif // _LIBCUDACXX_HAS_NO_LONG_LONG using ::div; using ::ldiv; -#ifndef _LIBCUDACXX_HAS_NO_LONG_LONG +# ifndef _LIBCUDACXX_HAS_NO_LONG_LONG using ::lldiv; -#endif // _LIBCUDACXX_HAS_NO_LONG_LONG +# endif // _LIBCUDACXX_HAS_NO_LONG_LONG using ::mblen; -using ::mbtowc; -using ::wctomb; using ::mbstowcs; +using ::mbtowc; using ::wcstombs; -#if defined(_LIBCUDACXX_HAS_QUICK_EXIT) +using ::wctomb; +# if defined(_LIBCUDACXX_HAS_QUICK_EXIT) using ::at_quick_exit; using ::quick_exit; -#endif -#if _CCCL_STD_VER > 2014 && defined(_LIBCUDACXX_HAS_C11_FEATURES) +# endif +# if _CCCL_STD_VER > 2014 && defined(_LIBCUDACXX_HAS_C11_FEATURES) using ::aligned_alloc; -#endif +# endif #endif // !defined(_CCCL_COMPILER_NVRTC) _LIBCUDACXX_END_NAMESPACE_STD #include //__cuda_std__ -#endif // _LIBCUDACXX_CSTDLIB +#endif // _LIBCUDACXX_CSTDLIB diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cstring b/libcudacxx/include/cuda/std/detail/libcxx/include/cstring index a6fb4c326b1..6b3d55163c7 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cstring +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cstring @@ -67,9 +67,9 @@ size_t strlen(const char* s); #endif // no system header #if defined(_CCCL_COMPILER_MSVC) -#include +# include #else // ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv -#include +# include #endif // !_CCCL_COMPILER_MSVC _LIBCUDACXX_BEGIN_NAMESPACE_STD @@ -96,9 +96,9 @@ using ::strrchr; using ::strspn; using ::strstr; using ::strxfrm; -#ifndef _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +# ifndef _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS using ::strtok; -#endif +# endif using ::strerror; using ::strlen; #endif // _CCCL_COMPILER_NVRTC diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/ctime b/libcudacxx/include/cuda/std/detail/libcxx/include/ctime index 0377595fb0a..f23b290ef2c 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/ctime +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/ctime @@ -56,7 +56,7 @@ int timespec_get( struct timespec *ts, int base); // C++17 #endif // no system header #ifndef _CCCL_COMPILER_NVRTC -#include +# include #else typedef long long int time_t; #endif // _CCCL_COMPILER_NVRTC @@ -72,27 +72,27 @@ using ::time_t; #ifndef _CCCL_COMPILER_NVRTC using ::tm; -#if _CCCL_STD_VER > 2014 && defined(_LIBCUDACXX_HAS_C11_FEATURES) +# if _CCCL_STD_VER > 2014 && defined(_LIBCUDACXX_HAS_C11_FEATURES) using ::timespec; -#endif +# endif using ::clock; using ::difftime; using ::mktime; using ::time; -#ifndef _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +# ifndef _LIBCUDACXX_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS using ::asctime; using ::ctime; using ::gmtime; using ::localtime; -#endif +# endif using ::strftime; -#if _CCCL_STD_VER > 2014 && defined(_LIBCUDACXX_HAS_TIMESPEC_GET) +# if _CCCL_STD_VER > 2014 && defined(_LIBCUDACXX_HAS_TIMESPEC_GET) using ::timespec_get; -#endif +# endif #endif // _CCCL_COMPILER_NVRTC _LIBCUDACXX_END_NAMESPACE_STD #include //__cuda_std__ -#endif // _LIBCUDACXX_CTIME +#endif // _LIBCUDACXX_CTIME diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/exception b/libcudacxx/include/cuda/std/detail/libcxx/include/exception index 5c7054df328..ad8948e31c1 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/exception +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/exception @@ -88,11 +88,10 @@ template void rethrow_if_nested(const E& e); # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include - +#include // all public C++ headers provide the assertion handler #include -#endif // _LIBCUDACXX_EXCEPTION +#endif // _LIBCUDACXX_EXCEPTION diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/expected b/libcudacxx/include/cuda/std/detail/libcxx/include/expected index e1697de1af6..14c34ed9533 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/expected +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/expected @@ -33,7 +33,6 @@ namespace std { #include #include #include - #include #endif // _LIBCUDACXX_EXPECTED diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/functional b/libcudacxx/include/cuda/std/detail/libcxx/include/functional index d5b0192789c..0c83d9c8d93 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/functional +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/functional @@ -298,7 +298,8 @@ public: }; template -pointer_to_binary_function ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 +pointer_to_binary_function ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in +C++17 template // deprecated in C++11, removed in C++17 class mem_fun_t : public unary_function @@ -316,8 +317,9 @@ public: S operator()(T* p, A x) const; }; -template mem_fun_t mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 -template mem_fun1_t mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 +template mem_fun_t mem_fun(S (T::*f)()); // deprecated in C++11, removed in +C++17 template mem_fun1_t mem_fun(S (T::*f)(A)); // deprecated in C++11, removed +in C++17 template class mem_fun_ref_t : public unary_function // deprecated in C++11, removed in C++17 @@ -335,8 +337,9 @@ public: S operator()(T& p, A x) const; }; -template mem_fun_ref_t mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 -template mem_fun1_ref_t mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 +template mem_fun_ref_t mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed +in C++17 template mem_fun1_ref_t mem_fun_ref(S (T::*f)(A)); // deprecated in +C++11, removed in C++17 template class const_mem_fun_t : public unary_function // deprecated in C++11, removed in C++17 @@ -354,8 +357,9 @@ public: S operator()(const T* p, A x) const; }; -template const_mem_fun_t mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 -template const_mem_fun1_t mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 +template const_mem_fun_t mem_fun(S (T::*f)() const); // deprecated in C++11, +removed in C++17 template const_mem_fun1_t mem_fun(S (T::*f)(A) const); // +deprecated in C++11, removed in C++17 template class const_mem_fun_ref_t : public unary_function // deprecated in C++11, removed in C++17 @@ -373,8 +377,9 @@ public: S operator()(const T& p, A x) const; }; -template const_mem_fun_ref_t mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 -template const_mem_fun1_ref_t mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 +template const_mem_fun_ref_t mem_fun_ref(S (T::*f)() const); // deprecated in +C++11, removed in C++17 template const_mem_fun1_ref_t mem_fun_ref(S (T::*f)(A) +const); // deprecated in C++11, removed in C++17 template unspecified mem_fn(R T::*); @@ -508,17 +513,16 @@ POLICY: For non-variadic implementations, the number of arguments is limited #endif // no system header #ifdef __cuda_std__ -#ifndef _CCCL_COMPILER_NVRTC -#include -#endif // _CCCL_COMPILER_NVRTC +# ifndef _CCCL_COMPILER_NVRTC +# include +# endif // _CCCL_COMPILER_NVRTC #endif // __cuda_std__ -#include #include #include +#include #include #include -#include #include #include #include @@ -541,8 +545,8 @@ POLICY: For non-variadic implementations, the number of arguments is limited #include #include #include - +#include #include // for forward declarations of vector and string. #include -#endif // _LIBCUDACXX_FUNCTIONAL +#endif // _LIBCUDACXX_FUNCTIONAL diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/initializer_list b/libcudacxx/include/cuda/std/detail/libcxx/include/initializer_list index fbc752e93fd..7c4d1203f92 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/initializer_list +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/initializer_list @@ -53,11 +53,11 @@ template const E* end(initializer_list il) noexcept; // constexpr in #endif // no system header #if !defined(_CCCL_COMPILER_NVRTC) -#include +# include #endif // !_CCCL_COMPILER_NVRTC _LIBCUDACXX_BEGIN_NAMESPACE_STD - using ::std::initializer_list; +using ::std::initializer_list; _LIBCUDACXX_END_NAMESPACE_STD -#endif // _LIBCUDACXX_INITIALIZER_LIST +#endif // _LIBCUDACXX_INITIALIZER_LIST diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/iosfwd b/libcudacxx/include/cuda/std/detail/libcxx/include/iosfwd index 8acf2e2e12f..833fdb1be0f 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/iosfwd +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/iosfwd @@ -101,110 +101,107 @@ typedef fpos::state_type> wstreampos; # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include +#include // all public C++ headers provide the assertion handler #include _LIBCUDACXX_BEGIN_NAMESPACE_STD class _LIBCUDACXX_TYPE_VIS ios_base; -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_ios; - -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_streambuf; -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_istream; -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_ostream; -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_iostream; - -template , - class _Allocator = allocator<_CharT> > - class _LIBCUDACXX_TEMPLATE_VIS basic_stringbuf; -template , - class _Allocator = allocator<_CharT> > - class _LIBCUDACXX_TEMPLATE_VIS basic_istringstream; -template , - class _Allocator = allocator<_CharT> > - class _LIBCUDACXX_TEMPLATE_VIS basic_ostringstream; -template , - class _Allocator = allocator<_CharT> > - class _LIBCUDACXX_TEMPLATE_VIS basic_stringstream; - -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_filebuf; -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_ifstream; -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_ofstream; -template > - class _LIBCUDACXX_TEMPLATE_VIS basic_fstream; - -template > - class _LIBCUDACXX_TEMPLATE_VIS istreambuf_iterator; -template > - class _LIBCUDACXX_TEMPLATE_VIS ostreambuf_iterator; - -typedef basic_ios ios; -typedef basic_ios wios; - -typedef basic_streambuf streambuf; -typedef basic_istream istream; -typedef basic_ostream ostream; -typedef basic_iostream iostream; - -typedef basic_stringbuf stringbuf; -typedef basic_istringstream istringstream; -typedef basic_ostringstream ostringstream; -typedef basic_stringstream stringstream; - -typedef basic_filebuf filebuf; -typedef basic_ifstream ifstream; -typedef basic_ofstream ofstream; -typedef basic_fstream fstream; - -typedef basic_streambuf wstreambuf; -typedef basic_istream wistream; -typedef basic_ostream wostream; -typedef basic_iostream wiostream; - -typedef basic_stringbuf wstringbuf; +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_ios; + +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_streambuf; +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_istream; +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_ostream; +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_iostream; + +template , class _Allocator = allocator<_CharT>> +class _LIBCUDACXX_TEMPLATE_VIS basic_stringbuf; +template , class _Allocator = allocator<_CharT>> +class _LIBCUDACXX_TEMPLATE_VIS basic_istringstream; +template , class _Allocator = allocator<_CharT>> +class _LIBCUDACXX_TEMPLATE_VIS basic_ostringstream; +template , class _Allocator = allocator<_CharT>> +class _LIBCUDACXX_TEMPLATE_VIS basic_stringstream; + +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_filebuf; +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_ifstream; +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_ofstream; +template > +class _LIBCUDACXX_TEMPLATE_VIS basic_fstream; + +template > +class _LIBCUDACXX_TEMPLATE_VIS istreambuf_iterator; +template > +class _LIBCUDACXX_TEMPLATE_VIS ostreambuf_iterator; + +typedef basic_ios ios; +typedef basic_ios wios; + +typedef basic_streambuf streambuf; +typedef basic_istream istream; +typedef basic_ostream ostream; +typedef basic_iostream iostream; + +typedef basic_stringbuf stringbuf; +typedef basic_istringstream istringstream; +typedef basic_ostringstream ostringstream; +typedef basic_stringstream stringstream; + +typedef basic_filebuf filebuf; +typedef basic_ifstream ifstream; +typedef basic_ofstream ofstream; +typedef basic_fstream fstream; + +typedef basic_streambuf wstreambuf; +typedef basic_istream wistream; +typedef basic_ostream wostream; +typedef basic_iostream wiostream; + +typedef basic_stringbuf wstringbuf; typedef basic_istringstream wistringstream; typedef basic_ostringstream wostringstream; -typedef basic_stringstream wstringstream; +typedef basic_stringstream wstringstream; -typedef basic_filebuf wfilebuf; -typedef basic_ifstream wifstream; -typedef basic_ofstream wofstream; -typedef basic_fstream wfstream; +typedef basic_filebuf wfilebuf; +typedef basic_ifstream wifstream; +typedef basic_ofstream wofstream; +typedef basic_fstream wfstream; #if !defined(_LIBCUDACXX_HAS_NO_WCHAR_H) -template class _LIBCUDACXX_TEMPLATE_VIS fpos; -typedef fpos streampos; -typedef fpos wstreampos; -#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T -typedef fpos u8streampos; -#endif -#ifndef _LIBCUDACXX_HAS_NO_UNICODE_CHARS -typedef fpos u16streampos; -typedef fpos u32streampos; -#endif // _LIBCUDACXX_HAS_NO_UNICODE_CHARS +template +class _LIBCUDACXX_TEMPLATE_VIS fpos; +typedef fpos streampos; +typedef fpos wstreampos; +# ifndef _LIBCUDACXX_NO_HAS_CHAR8_T +typedef fpos u8streampos; +# endif +# ifndef _LIBCUDACXX_HAS_NO_UNICODE_CHARS +typedef fpos u16streampos; +typedef fpos u32streampos; +# endif // _LIBCUDACXX_HAS_NO_UNICODE_CHARS #endif #if defined(_NEWLIB_VERSION) // On newlib, off_t is 'long int' -typedef long int streamoff; // for char_traits in +typedef long int streamoff; // for char_traits in #else -typedef long long streamoff; // for char_traits in +typedef long long streamoff; // for char_traits in #endif // Include other forward declarations here -template > +template > class _LIBCUDACXX_TEMPLATE_VIS vector; _LIBCUDACXX_END_NAMESPACE_STD -#endif // _LIBCUDACXX_IOSFWD +#endif // _LIBCUDACXX_IOSFWD diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/iterator b/libcudacxx/include/cuda/std/detail/libcxx/include/iterator index 5f1f42cb513..ee065ad475b 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/iterator +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/iterator @@ -685,7 +685,6 @@ template constexpr const E* data(initializer_list il) noexcept; # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include @@ -726,8 +725,9 @@ template constexpr const E* data(initializer_list il) noexcept; #include #include #include -#include +#include // all public C++ headers provide the assertion handler #include // for forward declarations of vector and string. +#include #include #include @@ -744,17 +744,17 @@ struct __libcpp_is_trivial_iterator : public _LIBCUDACXX_BOOL_CONSTANT(is_pointe {}; template -struct __libcpp_is_trivial_iterator > +struct __libcpp_is_trivial_iterator> : public _LIBCUDACXX_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template -struct __libcpp_is_trivial_iterator > +struct __libcpp_is_trivial_iterator> : public _LIBCUDACXX_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; template -struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > +struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter>> : public _LIBCUDACXX_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/latch b/libcudacxx/include/cuda/std/detail/libcxx/include/latch index 2dcac0588be..28c9e25d0d4 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/latch +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/latch @@ -48,74 +48,74 @@ namespace std # pragma system_header #endif // no system header +#include #include // all public C++ headers provide the assertion handler #include -#include #include #ifdef _LIBCUDACXX_HAS_NO_THREADS -# error is not supported on this single threaded system +# error is not supported on this single threaded system #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD -# if _LIBCUDACXX_CUDA_ABI_VERSION < 3 +#if _LIBCUDACXX_CUDA_ABI_VERSION < 3 # define _LIBCUDACXX_LATCH_ALIGNMENT alignas(64) -# else +#else # define _LIBCUDACXX_LATCH_ALIGNMENT -# endif +#endif -template +template class __latch_base { - _LIBCUDACXX_LATCH_ALIGNMENT __atomic_base __counter; + _LIBCUDACXX_LATCH_ALIGNMENT __atomic_base __counter; + public: - inline _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit __latch_base(ptrdiff_t __expected) - : __counter(__expected) { } + inline _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit __latch_base(ptrdiff_t __expected) + : __counter(__expected) + {} - ~__latch_base() = default; - __latch_base(const __latch_base&) = delete; - __latch_base& operator=(const __latch_base&) = delete; + ~__latch_base() = default; + __latch_base(const __latch_base&) = delete; + __latch_base& operator=(const __latch_base&) = delete; - inline _LIBCUDACXX_INLINE_VISIBILITY - void count_down(ptrdiff_t __update = 1) - { - _LIBCUDACXX_ASSERT(__update > 0, ""); - auto const __old = __counter.fetch_sub(__update, memory_order_release); - _LIBCUDACXX_ASSERT(__old >= __update, ""); - if(__old == __update) - __counter.notify_all(); - } - inline _LIBCUDACXX_INLINE_VISIBILITY - bool try_wait() const noexcept - { - return __counter.load(memory_order_acquire) == 0; - } - inline _LIBCUDACXX_INLINE_VISIBILITY - void wait() const + inline _LIBCUDACXX_INLINE_VISIBILITY void count_down(ptrdiff_t __update = 1) + { + _LIBCUDACXX_ASSERT(__update > 0, ""); + auto const __old = __counter.fetch_sub(__update, memory_order_release); + _LIBCUDACXX_ASSERT(__old >= __update, ""); + if (__old == __update) { - while(1) { - auto const __current = __counter.load(memory_order_acquire); - if(__current == 0) - return; - __counter.wait(__current, memory_order_relaxed) - ; - } + __counter.notify_all(); } - inline _LIBCUDACXX_INLINE_VISIBILITY - void arrive_and_wait(ptrdiff_t __update = 1) + } + inline _LIBCUDACXX_INLINE_VISIBILITY bool try_wait() const noexcept + { + return __counter.load(memory_order_acquire) == 0; + } + inline _LIBCUDACXX_INLINE_VISIBILITY void wait() const + { + while (1) { - count_down(__update); - wait(); + auto const __current = __counter.load(memory_order_acquire); + if (__current == 0) + { + return; + } + __counter.wait(__current, memory_order_relaxed); } + } + inline _LIBCUDACXX_INLINE_VISIBILITY void arrive_and_wait(ptrdiff_t __update = 1) + { + count_down(__update); + wait(); + } - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr ptrdiff_t max() noexcept - { - return numeric_limits::max(); - } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr ptrdiff_t max() noexcept + { + return numeric_limits::max(); + } }; using latch = __latch_base<>; diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/limits b/libcudacxx/include/cuda/std/detail/libcxx/include/limits index cdedd84d2a3..740dcd4dd1d 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/limits +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/limits @@ -112,82 +112,109 @@ template<> class numeric_limits; # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include +#include // all public C++ headers provide the assertion handler #include #include #include #if defined(_CCCL_COMPILER_MSVC) -#include +# include #endif // _LIBCUDACXX_MSVCRT #if defined(_CCCL_COMPILER_IBM) -#include +# include #endif // _CCCL_COMPILER_IBM _LIBCUDACXX_BEGIN_NAMESPACE_STD enum float_round_style { - round_indeterminate = -1, - round_toward_zero = 0, - round_to_nearest = 1, - round_toward_infinity = 2, - round_toward_neg_infinity = 3 + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3 }; enum float_denorm_style { - denorm_indeterminate = -1, - denorm_absent = 0, - denorm_present = 1 + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 }; template ::value> class __libcpp_numeric_limits { protected: - typedef _Tp type; - - static constexpr bool is_specialized = false; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return type();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return type();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return type();} - - static constexpr int digits = 0; - static constexpr int digits10 = 0; - static constexpr int max_digits10 = 0; - static constexpr bool is_signed = false; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = 0; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return type();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return type();} - - static constexpr int min_exponent = 0; - static constexpr int min_exponent10 = 0; - static constexpr int max_exponent = 0; - static constexpr int max_exponent10 = 0; - - static constexpr bool has_infinity = false; - static constexpr bool has_quiet_NaN = false; - static constexpr bool has_signaling_NaN = false; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return type();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return type();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return type();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return type();} - - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_toward_zero; + typedef _Tp type; + + static constexpr bool is_specialized = false; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return type(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return type(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return type(); + } + + static constexpr int digits = 0; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + static constexpr bool is_signed = false; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 0; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return type(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return type(); + } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return type(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return type(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return type(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return type(); + } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; }; _CCCL_DIAG_PUSH @@ -195,647 +222,908 @@ _CCCL_DIAG_SUPPRESS_MSVC(4309) template struct __libcpp_compute_min { - static constexpr _Tp value = static_cast<_Tp>(_Tp(1) << __digits); + static constexpr _Tp value = static_cast<_Tp>(_Tp(1) << __digits); }; _CCCL_DIAG_POP template struct __libcpp_compute_min<_Tp, __digits, false> { - static constexpr _Tp value = _Tp(0); + static constexpr _Tp value = _Tp(0); }; template class __libcpp_numeric_limits<_Tp, true> { protected: - typedef _Tp type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = type(-1) < type(0); - static constexpr int digits = static_cast(sizeof(type) * __CHAR_BIT__ - is_signed); - static constexpr int digits10 = digits * 3 / 10; - static constexpr int max_digits10 = 0; - static constexpr type __min = __libcpp_compute_min::value; - static constexpr type __max = is_signed ? type(type(~0) ^ __min) : type(~0); - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __min;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __max;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return min();} - - static constexpr bool is_integer = true; - static constexpr bool is_exact = true; - static constexpr int radix = 2; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return type(0);} - - static constexpr int min_exponent = 0; - static constexpr int min_exponent10 = 0; - static constexpr int max_exponent = 0; - static constexpr int max_exponent10 = 0; - - static constexpr bool has_infinity = false; - static constexpr bool has_quiet_NaN = false; - static constexpr bool has_signaling_NaN = false; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return type(0);} - - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = !_CUDA_VSTD::is_signed<_Tp>::value; - -#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || \ - defined(__wasm__) - static constexpr bool traps = true; + typedef _Tp type; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = type(-1) < type(0); + static constexpr int digits = static_cast(sizeof(type) * __CHAR_BIT__ - is_signed); + static constexpr int digits10 = digits * 3 / 10; + static constexpr int max_digits10 = 0; + static constexpr type __min = __libcpp_compute_min::value; + static constexpr type __max = is_signed ? type(type(~0) ^ __min) : type(~0); + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __min; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __max; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return min(); + } + + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return type(0); + } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return type(0); + } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = !_CUDA_VSTD::is_signed<_Tp>::value; + +#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || defined(__wasm__) + static constexpr bool traps = true; #else - static constexpr bool traps = false; + static constexpr bool traps = false; #endif - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_toward_zero; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; }; template <> class __libcpp_numeric_limits { protected: - typedef bool type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = false; - static constexpr int digits = 1; - static constexpr int digits10 = 0; - static constexpr int max_digits10 = 0; - static constexpr type __min = false; - static constexpr type __max = true; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __min;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __max;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return min();} - - static constexpr bool is_integer = true; - static constexpr bool is_exact = true; - static constexpr int radix = 2; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return type(0);} - - static constexpr int min_exponent = 0; - static constexpr int min_exponent10 = 0; - static constexpr int max_exponent = 0; - static constexpr int max_exponent10 = 0; - - static constexpr bool has_infinity = false; - static constexpr bool has_quiet_NaN = false; - static constexpr bool has_signaling_NaN = false; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return type(0);} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return type(0);} - - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_toward_zero; + typedef bool type; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = false; + static constexpr int digits = 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + static constexpr type __min = false; + static constexpr type __max = true; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __min; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __max; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return min(); + } + + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return type(0); + } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return type(0); + } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; }; template <> class __libcpp_numeric_limits { protected: - typedef float type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = true; - static constexpr int digits = __FLT_MANT_DIG__; - static constexpr int digits10 = __FLT_DIG__; - static constexpr int max_digits10 = 2+(digits * 30103l)/100000l; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __FLT_MIN__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __FLT_MAX__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return -max();} - - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = __FLT_RADIX__; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return __FLT_EPSILON__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return 0.5F;} - - static constexpr int min_exponent = __FLT_MIN_EXP__; - static constexpr int min_exponent10 = __FLT_MIN_10_EXP__; - static constexpr int max_exponent = __FLT_MAX_EXP__; - static constexpr int max_exponent10 = __FLT_MAX_10_EXP__; - - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_present; - static constexpr bool has_denorm_loss = false; + typedef float type; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = true; + static constexpr int digits = __FLT_MANT_DIG__; + static constexpr int digits10 = __FLT_DIG__; + static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __FLT_MIN__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __FLT_MAX__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return -max(); + } + + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = __FLT_RADIX__; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return __FLT_EPSILON__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return 0.5F; + } + + static constexpr int min_exponent = __FLT_MIN_EXP__; + static constexpr int min_exponent10 = __FLT_MIN_10_EXP__; + static constexpr int max_exponent = __FLT_MAX_EXP__; + static constexpr int max_exponent10 = __FLT_MAX_10_EXP__; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = false; #ifdef _CCCL_COMPILER_NVRTC - _LIBCUDACXX_INLINE_VISIBILITY static type infinity() noexcept {return __builtin_huge_valf();} - _LIBCUDACXX_INLINE_VISIBILITY static type quiet_NaN() noexcept {return __builtin_nanf("");} - _LIBCUDACXX_INLINE_VISIBILITY static type signaling_NaN() noexcept {return __builtin_nansf("");} + _LIBCUDACXX_INLINE_VISIBILITY static type infinity() noexcept + { + return __builtin_huge_valf(); + } + _LIBCUDACXX_INLINE_VISIBILITY static type quiet_NaN() noexcept + { + return __builtin_nanf(""); + } + _LIBCUDACXX_INLINE_VISIBILITY static type signaling_NaN() noexcept + { + return __builtin_nansf(""); + } #else - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return __builtin_huge_valf();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return __builtin_nanf("");} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return __builtin_nansf("");} + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return __builtin_huge_valf(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return __builtin_nanf(""); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return __builtin_nansf(""); + } #endif - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return __FLT_DENORM_MIN__;} - - static constexpr bool is_iec559 = true; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return __FLT_DENORM_MIN__; + } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; }; template <> class __libcpp_numeric_limits { protected: - typedef double type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = true; - static constexpr int digits = __DBL_MANT_DIG__; - static constexpr int digits10 = __DBL_DIG__; - static constexpr int max_digits10 = 2+(digits * 30103l)/100000l; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __DBL_MIN__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __DBL_MAX__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return -max();} - - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = __FLT_RADIX__; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return __DBL_EPSILON__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return 0.5;} - - static constexpr int min_exponent = __DBL_MIN_EXP__; - static constexpr int min_exponent10 = __DBL_MIN_10_EXP__; - static constexpr int max_exponent = __DBL_MAX_EXP__; - static constexpr int max_exponent10 = __DBL_MAX_10_EXP__; - - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_present; - static constexpr bool has_denorm_loss = false; + typedef double type; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = true; + static constexpr int digits = __DBL_MANT_DIG__; + static constexpr int digits10 = __DBL_DIG__; + static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __DBL_MIN__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __DBL_MAX__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return -max(); + } + + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = __FLT_RADIX__; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return __DBL_EPSILON__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return 0.5; + } + + static constexpr int min_exponent = __DBL_MIN_EXP__; + static constexpr int min_exponent10 = __DBL_MIN_10_EXP__; + static constexpr int max_exponent = __DBL_MAX_EXP__; + static constexpr int max_exponent10 = __DBL_MAX_10_EXP__; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = false; #ifdef _CCCL_COMPILER_NVRTC - _LIBCUDACXX_INLINE_VISIBILITY static type infinity() noexcept {return __builtin_huge_val();} - _LIBCUDACXX_INLINE_VISIBILITY static type quiet_NaN() noexcept {return __builtin_nan("");} - _LIBCUDACXX_INLINE_VISIBILITY static type signaling_NaN() noexcept {return __builtin_nans("");} + _LIBCUDACXX_INLINE_VISIBILITY static type infinity() noexcept + { + return __builtin_huge_val(); + } + _LIBCUDACXX_INLINE_VISIBILITY static type quiet_NaN() noexcept + { + return __builtin_nan(""); + } + _LIBCUDACXX_INLINE_VISIBILITY static type signaling_NaN() noexcept + { + return __builtin_nans(""); + } #else - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return __builtin_huge_val();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return __builtin_nan("");} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return __builtin_nans("");} + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return __builtin_huge_val(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return __builtin_nan(""); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return __builtin_nans(""); + } #endif - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return __DBL_DENORM_MIN__;} - - static constexpr bool is_iec559 = true; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return __DBL_DENORM_MIN__; + } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; }; template <> class __libcpp_numeric_limits { #ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE -protected: - typedef long double type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = true; - static constexpr int digits = __LDBL_MANT_DIG__; - static constexpr int digits10 = __LDBL_DIG__; - static constexpr int max_digits10 = 2+(digits * 30103l)/100000l; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __LDBL_MIN__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __LDBL_MAX__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return -max();} - - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = __FLT_RADIX__; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return __LDBL_EPSILON__;} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return 0.5L;} - - static constexpr int min_exponent = __LDBL_MIN_EXP__; - static constexpr int min_exponent10 = __LDBL_MIN_10_EXP__; - static constexpr int max_exponent = __LDBL_MAX_EXP__; - static constexpr int max_exponent10 = __LDBL_MAX_10_EXP__; - - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_present; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return __builtin_huge_vall();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return __builtin_nanl("");} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return __builtin_nansl("");} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return __LDBL_DENORM_MIN__;} - -#if (defined(__ppc__) || defined(__ppc64__) || defined(__PPC64__)) - static constexpr bool is_iec559 = false; -#else - static constexpr bool is_iec559 = true; -#endif - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; +protected: + typedef long double type; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = true; + static constexpr int digits = __LDBL_MANT_DIG__; + static constexpr int digits10 = __LDBL_DIG__; + static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __LDBL_MIN__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __LDBL_MAX__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return -max(); + } + + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = __FLT_RADIX__; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return __LDBL_EPSILON__; + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return 0.5L; + } + + static constexpr int min_exponent = __LDBL_MIN_EXP__; + static constexpr int min_exponent10 = __LDBL_MIN_10_EXP__; + static constexpr int max_exponent = __LDBL_MAX_EXP__; + static constexpr int max_exponent10 = __LDBL_MAX_10_EXP__; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return __builtin_huge_vall(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return __builtin_nanl(""); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return __builtin_nansl(""); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return __LDBL_DENORM_MIN__; + } + +# if (defined(__ppc__) || defined(__ppc64__) || defined(__PPC64__)) + static constexpr bool is_iec559 = false; +# else + static constexpr bool is_iec559 = true; +# endif + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; #endif }; template -class _LIBCUDACXX_TEMPLATE_VIS numeric_limits - : private __libcpp_numeric_limits<__remove_cv_t<_Tp>> +class _LIBCUDACXX_TEMPLATE_VIS numeric_limits : private __libcpp_numeric_limits<__remove_cv_t<_Tp>> { - typedef __libcpp_numeric_limits<__remove_cv_t<_Tp>> __base; - typedef typename __base::type type; + typedef __libcpp_numeric_limits<__remove_cv_t<_Tp>> __base; + typedef typename __base::type type; + public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __base::min();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __base::max();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return __base::lowest();} - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return __base::epsilon();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return __base::round_error();} - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return __base::infinity();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return __base::quiet_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return __base::signaling_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return __base::denorm_min();} - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; + static constexpr bool is_specialized = __base::is_specialized; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __base::min(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __base::max(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return __base::lowest(); + } + + static constexpr int digits = __base::digits; + static constexpr int digits10 = __base::digits10; + static constexpr int max_digits10 = __base::max_digits10; + static constexpr bool is_signed = __base::is_signed; + static constexpr bool is_integer = __base::is_integer; + static constexpr bool is_exact = __base::is_exact; + static constexpr int radix = __base::radix; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return __base::epsilon(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return __base::round_error(); + } + + static constexpr int min_exponent = __base::min_exponent; + static constexpr int min_exponent10 = __base::min_exponent10; + static constexpr int max_exponent = __base::max_exponent; + static constexpr int max_exponent10 = __base::max_exponent10; + + static constexpr bool has_infinity = __base::has_infinity; + static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; + static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; + static constexpr float_denorm_style has_denorm = __base::has_denorm; + static constexpr bool has_denorm_loss = __base::has_denorm_loss; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return __base::infinity(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return __base::quiet_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return __base::signaling_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return __base::denorm_min(); + } + + static constexpr bool is_iec559 = __base::is_iec559; + static constexpr bool is_bounded = __base::is_bounded; + static constexpr bool is_modulo = __base::is_modulo; + + static constexpr bool traps = __base::traps; + static constexpr bool tinyness_before = __base::tinyness_before; + static constexpr float_round_style round_style = __base::round_style; }; template - constexpr bool numeric_limits<_Tp>::is_specialized; +constexpr bool numeric_limits<_Tp>::is_specialized; template - constexpr int numeric_limits<_Tp>::digits; +constexpr int numeric_limits<_Tp>::digits; template - constexpr int numeric_limits<_Tp>::digits10; +constexpr int numeric_limits<_Tp>::digits10; template - constexpr int numeric_limits<_Tp>::max_digits10; +constexpr int numeric_limits<_Tp>::max_digits10; template - constexpr bool numeric_limits<_Tp>::is_signed; +constexpr bool numeric_limits<_Tp>::is_signed; template - constexpr bool numeric_limits<_Tp>::is_integer; +constexpr bool numeric_limits<_Tp>::is_integer; template - constexpr bool numeric_limits<_Tp>::is_exact; +constexpr bool numeric_limits<_Tp>::is_exact; template - constexpr int numeric_limits<_Tp>::radix; +constexpr int numeric_limits<_Tp>::radix; template - constexpr int numeric_limits<_Tp>::min_exponent; +constexpr int numeric_limits<_Tp>::min_exponent; template - constexpr int numeric_limits<_Tp>::min_exponent10; +constexpr int numeric_limits<_Tp>::min_exponent10; template - constexpr int numeric_limits<_Tp>::max_exponent; +constexpr int numeric_limits<_Tp>::max_exponent; template - constexpr int numeric_limits<_Tp>::max_exponent10; +constexpr int numeric_limits<_Tp>::max_exponent10; template - constexpr bool numeric_limits<_Tp>::has_infinity; +constexpr bool numeric_limits<_Tp>::has_infinity; template - constexpr bool numeric_limits<_Tp>::has_quiet_NaN; +constexpr bool numeric_limits<_Tp>::has_quiet_NaN; template - constexpr bool numeric_limits<_Tp>::has_signaling_NaN; +constexpr bool numeric_limits<_Tp>::has_signaling_NaN; template - constexpr float_denorm_style numeric_limits<_Tp>::has_denorm; +constexpr float_denorm_style numeric_limits<_Tp>::has_denorm; template - constexpr bool numeric_limits<_Tp>::has_denorm_loss; +constexpr bool numeric_limits<_Tp>::has_denorm_loss; template - constexpr bool numeric_limits<_Tp>::is_iec559; +constexpr bool numeric_limits<_Tp>::is_iec559; template - constexpr bool numeric_limits<_Tp>::is_bounded; +constexpr bool numeric_limits<_Tp>::is_bounded; template - constexpr bool numeric_limits<_Tp>::is_modulo; +constexpr bool numeric_limits<_Tp>::is_modulo; template - constexpr bool numeric_limits<_Tp>::traps; +constexpr bool numeric_limits<_Tp>::traps; template - constexpr bool numeric_limits<_Tp>::tinyness_before; +constexpr bool numeric_limits<_Tp>::tinyness_before; template - constexpr float_round_style numeric_limits<_Tp>::round_style; +constexpr float_round_style numeric_limits<_Tp>::round_style; template -class _LIBCUDACXX_TEMPLATE_VIS numeric_limits - : private numeric_limits<_Tp> +class _LIBCUDACXX_TEMPLATE_VIS numeric_limits : private numeric_limits<_Tp> { - typedef numeric_limits<_Tp> __base; - typedef _Tp type; + typedef numeric_limits<_Tp> __base; + typedef _Tp type; + public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __base::min();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __base::max();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return __base::lowest();} - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return __base::epsilon();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return __base::round_error();} - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return __base::infinity();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return __base::quiet_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return __base::signaling_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return __base::denorm_min();} - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; + static constexpr bool is_specialized = __base::is_specialized; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __base::min(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __base::max(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return __base::lowest(); + } + + static constexpr int digits = __base::digits; + static constexpr int digits10 = __base::digits10; + static constexpr int max_digits10 = __base::max_digits10; + static constexpr bool is_signed = __base::is_signed; + static constexpr bool is_integer = __base::is_integer; + static constexpr bool is_exact = __base::is_exact; + static constexpr int radix = __base::radix; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return __base::epsilon(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return __base::round_error(); + } + + static constexpr int min_exponent = __base::min_exponent; + static constexpr int min_exponent10 = __base::min_exponent10; + static constexpr int max_exponent = __base::max_exponent; + static constexpr int max_exponent10 = __base::max_exponent10; + + static constexpr bool has_infinity = __base::has_infinity; + static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; + static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; + static constexpr float_denorm_style has_denorm = __base::has_denorm; + static constexpr bool has_denorm_loss = __base::has_denorm_loss; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return __base::infinity(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return __base::quiet_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return __base::signaling_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return __base::denorm_min(); + } + + static constexpr bool is_iec559 = __base::is_iec559; + static constexpr bool is_bounded = __base::is_bounded; + static constexpr bool is_modulo = __base::is_modulo; + + static constexpr bool traps = __base::traps; + static constexpr bool tinyness_before = __base::tinyness_before; + static constexpr float_round_style round_style = __base::round_style; }; template - constexpr bool numeric_limits::is_specialized; +constexpr bool numeric_limits::is_specialized; template - constexpr int numeric_limits::digits; +constexpr int numeric_limits::digits; template - constexpr int numeric_limits::digits10; +constexpr int numeric_limits::digits10; template - constexpr int numeric_limits::max_digits10; +constexpr int numeric_limits::max_digits10; template - constexpr bool numeric_limits::is_signed; +constexpr bool numeric_limits::is_signed; template - constexpr bool numeric_limits::is_integer; +constexpr bool numeric_limits::is_integer; template - constexpr bool numeric_limits::is_exact; +constexpr bool numeric_limits::is_exact; template - constexpr int numeric_limits::radix; +constexpr int numeric_limits::radix; template - constexpr int numeric_limits::min_exponent; +constexpr int numeric_limits::min_exponent; template - constexpr int numeric_limits::min_exponent10; +constexpr int numeric_limits::min_exponent10; template - constexpr int numeric_limits::max_exponent; +constexpr int numeric_limits::max_exponent; template - constexpr int numeric_limits::max_exponent10; +constexpr int numeric_limits::max_exponent10; template - constexpr bool numeric_limits::has_infinity; +constexpr bool numeric_limits::has_infinity; template - constexpr bool numeric_limits::has_quiet_NaN; +constexpr bool numeric_limits::has_quiet_NaN; template - constexpr bool numeric_limits::has_signaling_NaN; +constexpr bool numeric_limits::has_signaling_NaN; template - constexpr float_denorm_style numeric_limits::has_denorm; +constexpr float_denorm_style numeric_limits::has_denorm; template - constexpr bool numeric_limits::has_denorm_loss; +constexpr bool numeric_limits::has_denorm_loss; template - constexpr bool numeric_limits::is_iec559; +constexpr bool numeric_limits::is_iec559; template - constexpr bool numeric_limits::is_bounded; +constexpr bool numeric_limits::is_bounded; template - constexpr bool numeric_limits::is_modulo; +constexpr bool numeric_limits::is_modulo; template - constexpr bool numeric_limits::traps; +constexpr bool numeric_limits::traps; template - constexpr bool numeric_limits::tinyness_before; +constexpr bool numeric_limits::tinyness_before; template - constexpr float_round_style numeric_limits::round_style; +constexpr float_round_style numeric_limits::round_style; template -class _LIBCUDACXX_TEMPLATE_VIS numeric_limits - : private numeric_limits<_Tp> +class _LIBCUDACXX_TEMPLATE_VIS numeric_limits : private numeric_limits<_Tp> { - typedef numeric_limits<_Tp> __base; - typedef _Tp type; + typedef numeric_limits<_Tp> __base; + typedef _Tp type; + public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __base::min();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __base::max();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return __base::lowest();} - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return __base::epsilon();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return __base::round_error();} - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return __base::infinity();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return __base::quiet_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return __base::signaling_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return __base::denorm_min();} - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; + static constexpr bool is_specialized = __base::is_specialized; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __base::min(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __base::max(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return __base::lowest(); + } + + static constexpr int digits = __base::digits; + static constexpr int digits10 = __base::digits10; + static constexpr int max_digits10 = __base::max_digits10; + static constexpr bool is_signed = __base::is_signed; + static constexpr bool is_integer = __base::is_integer; + static constexpr bool is_exact = __base::is_exact; + static constexpr int radix = __base::radix; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return __base::epsilon(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return __base::round_error(); + } + + static constexpr int min_exponent = __base::min_exponent; + static constexpr int min_exponent10 = __base::min_exponent10; + static constexpr int max_exponent = __base::max_exponent; + static constexpr int max_exponent10 = __base::max_exponent10; + + static constexpr bool has_infinity = __base::has_infinity; + static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; + static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; + static constexpr float_denorm_style has_denorm = __base::has_denorm; + static constexpr bool has_denorm_loss = __base::has_denorm_loss; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return __base::infinity(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return __base::quiet_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return __base::signaling_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return __base::denorm_min(); + } + + static constexpr bool is_iec559 = __base::is_iec559; + static constexpr bool is_bounded = __base::is_bounded; + static constexpr bool is_modulo = __base::is_modulo; + + static constexpr bool traps = __base::traps; + static constexpr bool tinyness_before = __base::tinyness_before; + static constexpr float_round_style round_style = __base::round_style; }; template - constexpr bool numeric_limits::is_specialized; +constexpr bool numeric_limits::is_specialized; template - constexpr int numeric_limits::digits; +constexpr int numeric_limits::digits; template - constexpr int numeric_limits::digits10; +constexpr int numeric_limits::digits10; template - constexpr int numeric_limits::max_digits10; +constexpr int numeric_limits::max_digits10; template - constexpr bool numeric_limits::is_signed; +constexpr bool numeric_limits::is_signed; template - constexpr bool numeric_limits::is_integer; +constexpr bool numeric_limits::is_integer; template - constexpr bool numeric_limits::is_exact; +constexpr bool numeric_limits::is_exact; template - constexpr int numeric_limits::radix; +constexpr int numeric_limits::radix; template - constexpr int numeric_limits::min_exponent; +constexpr int numeric_limits::min_exponent; template - constexpr int numeric_limits::min_exponent10; +constexpr int numeric_limits::min_exponent10; template - constexpr int numeric_limits::max_exponent; +constexpr int numeric_limits::max_exponent; template - constexpr int numeric_limits::max_exponent10; +constexpr int numeric_limits::max_exponent10; template - constexpr bool numeric_limits::has_infinity; +constexpr bool numeric_limits::has_infinity; template - constexpr bool numeric_limits::has_quiet_NaN; +constexpr bool numeric_limits::has_quiet_NaN; template - constexpr bool numeric_limits::has_signaling_NaN; +constexpr bool numeric_limits::has_signaling_NaN; template - constexpr float_denorm_style numeric_limits::has_denorm; +constexpr float_denorm_style numeric_limits::has_denorm; template - constexpr bool numeric_limits::has_denorm_loss; +constexpr bool numeric_limits::has_denorm_loss; template - constexpr bool numeric_limits::is_iec559; +constexpr bool numeric_limits::is_iec559; template - constexpr bool numeric_limits::is_bounded; +constexpr bool numeric_limits::is_bounded; template - constexpr bool numeric_limits::is_modulo; +constexpr bool numeric_limits::is_modulo; template - constexpr bool numeric_limits::traps; +constexpr bool numeric_limits::traps; template - constexpr bool numeric_limits::tinyness_before; +constexpr bool numeric_limits::tinyness_before; template - constexpr float_round_style numeric_limits::round_style; +constexpr float_round_style numeric_limits::round_style; template -class _LIBCUDACXX_TEMPLATE_VIS numeric_limits - : private numeric_limits<_Tp> +class _LIBCUDACXX_TEMPLATE_VIS numeric_limits : private numeric_limits<_Tp> { - typedef numeric_limits<_Tp> __base; - typedef _Tp type; + typedef numeric_limits<_Tp> __base; + typedef _Tp type; + public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept {return __base::min();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept {return __base::max();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept {return __base::lowest();} - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept {return __base::epsilon();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept {return __base::round_error();} - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept {return __base::infinity();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept {return __base::quiet_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept {return __base::signaling_NaN();} - _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept {return __base::denorm_min();} - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; + static constexpr bool is_specialized = __base::is_specialized; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type min() noexcept + { + return __base::min(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type max() noexcept + { + return __base::max(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type lowest() noexcept + { + return __base::lowest(); + } + + static constexpr int digits = __base::digits; + static constexpr int digits10 = __base::digits10; + static constexpr int max_digits10 = __base::max_digits10; + static constexpr bool is_signed = __base::is_signed; + static constexpr bool is_integer = __base::is_integer; + static constexpr bool is_exact = __base::is_exact; + static constexpr int radix = __base::radix; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type epsilon() noexcept + { + return __base::epsilon(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type round_error() noexcept + { + return __base::round_error(); + } + + static constexpr int min_exponent = __base::min_exponent; + static constexpr int min_exponent10 = __base::min_exponent10; + static constexpr int max_exponent = __base::max_exponent; + static constexpr int max_exponent10 = __base::max_exponent10; + + static constexpr bool has_infinity = __base::has_infinity; + static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; + static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; + static constexpr float_denorm_style has_denorm = __base::has_denorm; + static constexpr bool has_denorm_loss = __base::has_denorm_loss; + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type infinity() noexcept + { + return __base::infinity(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type quiet_NaN() noexcept + { + return __base::quiet_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type signaling_NaN() noexcept + { + return __base::signaling_NaN(); + } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr type denorm_min() noexcept + { + return __base::denorm_min(); + } + + static constexpr bool is_iec559 = __base::is_iec559; + static constexpr bool is_bounded = __base::is_bounded; + static constexpr bool is_modulo = __base::is_modulo; + + static constexpr bool traps = __base::traps; + static constexpr bool tinyness_before = __base::tinyness_before; + static constexpr float_round_style round_style = __base::round_style; }; template - constexpr bool numeric_limits::is_specialized; +constexpr bool numeric_limits::is_specialized; template - constexpr int numeric_limits::digits; +constexpr int numeric_limits::digits; template - constexpr int numeric_limits::digits10; +constexpr int numeric_limits::digits10; template - constexpr int numeric_limits::max_digits10; +constexpr int numeric_limits::max_digits10; template - constexpr bool numeric_limits::is_signed; +constexpr bool numeric_limits::is_signed; template - constexpr bool numeric_limits::is_integer; +constexpr bool numeric_limits::is_integer; template - constexpr bool numeric_limits::is_exact; +constexpr bool numeric_limits::is_exact; template - constexpr int numeric_limits::radix; +constexpr int numeric_limits::radix; template - constexpr int numeric_limits::min_exponent; +constexpr int numeric_limits::min_exponent; template - constexpr int numeric_limits::min_exponent10; +constexpr int numeric_limits::min_exponent10; template - constexpr int numeric_limits::max_exponent; +constexpr int numeric_limits::max_exponent; template - constexpr int numeric_limits::max_exponent10; +constexpr int numeric_limits::max_exponent10; template - constexpr bool numeric_limits::has_infinity; +constexpr bool numeric_limits::has_infinity; template - constexpr bool numeric_limits::has_quiet_NaN; +constexpr bool numeric_limits::has_quiet_NaN; template - constexpr bool numeric_limits::has_signaling_NaN; +constexpr bool numeric_limits::has_signaling_NaN; template - constexpr float_denorm_style numeric_limits::has_denorm; +constexpr float_denorm_style numeric_limits::has_denorm; template - constexpr bool numeric_limits::has_denorm_loss; +constexpr bool numeric_limits::has_denorm_loss; template - constexpr bool numeric_limits::is_iec559; +constexpr bool numeric_limits::is_iec559; template - constexpr bool numeric_limits::is_bounded; +constexpr bool numeric_limits::is_bounded; template - constexpr bool numeric_limits::is_modulo; +constexpr bool numeric_limits::is_modulo; template - constexpr bool numeric_limits::traps; +constexpr bool numeric_limits::traps; template - constexpr bool numeric_limits::tinyness_before; +constexpr bool numeric_limits::tinyness_before; template - constexpr float_round_style numeric_limits::round_style; +constexpr float_round_style numeric_limits::round_style; _LIBCUDACXX_END_NAMESPACE_STD #include //__cuda_std__ -#endif // _LIBCUDACXX_LIMITS +#endif // _LIBCUDACXX_LIMITS diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/mdspan b/libcudacxx/include/cuda/std/detail/libcxx/include/mdspan index dd469e6b8f6..8fe0e09d0a9 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/mdspan +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/mdspan @@ -46,19 +46,18 @@ #include -#include // all public C++ headers provide the assertion handler #include -#include -#include #include #include -#include +#include #include #include +#include #include +#include #include #include - +#include // all public C++ headers provide the assertion handler #include #endif // _LIBCUDACXX_MDSPAN diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/new b/libcudacxx/include/cuda/std/detail/libcxx/include/new index 7615bb0d326..a9ce3e694a0 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/new +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/new @@ -50,11 +50,10 @@ template constexpr T* launder(T* p) noexcept; // C++17 # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include - +#include // all public C++ headers provide the assertion handler #include #endif // _LIBCUDACXX_NEW diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/numeric b/libcudacxx/include/cuda/std/detail/libcxx/include/numeric deleted file mode 100644 index 76d49c5a26c..00000000000 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/numeric +++ /dev/null @@ -1,607 +0,0 @@ -// -*- C++ -*- -//===---------------------------- numeric ---------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCUDACXX_NUMERIC -#define _LIBCUDACXX_NUMERIC - -/* - numeric synopsis - -namespace std -{ - -#ifndef __cuda_std__ -template - T - accumulate(InputIterator first, InputIterator last, T init); - -template - T - accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); - -template - typename iterator_traits::value_type - reduce(InputIterator first, InputIterator last); // C++17 - -template - T - reduce(InputIterator first, InputIterator last, T init); // C++17 - -template - T - reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17 - -template - T - inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); - -template - T - inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, - T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); - - -template - T - transform_reduce(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, T init); // C++17 - -template - T - transform_reduce(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, T init, - BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17 - -template - T - transform_reduce(InputIterator first, InputIterator last, T init, - BinaryOperation binary_op, UnaryOperation unary_op); // C++17 - -template - OutputIterator - partial_sum(InputIterator first, InputIterator last, OutputIterator result); - -template - OutputIterator - partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); - -template - OutputIterator - exclusive_scan(InputIterator first, InputIterator last, - OutputIterator result, T init); // C++17 - -template - OutputIterator - exclusive_scan(InputIterator first, InputIterator last, - OutputIterator result, T init, BinaryOperation binary_op); // C++17 - -template - OutputIterator - inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17 - -template - OutputIterator - inclusive_scan(InputIterator first, InputIterator last, - OutputIterator result, BinaryOperation binary_op); // C++17 - -template - OutputIterator - inclusive_scan(InputIterator first, InputIterator last, - OutputIterator result, BinaryOperation binary_op, T init); // C++17 - -template - OutputIterator - transform_exclusive_scan(InputIterator first, InputIterator last, - OutputIterator result, T init, - BinaryOperation binary_op, UnaryOperation unary_op); // C++17 - -template - OutputIterator - transform_inclusive_scan(InputIterator first, InputIterator last, - OutputIterator result, - BinaryOperation binary_op, UnaryOperation unary_op); // C++17 - -template - OutputIterator - transform_inclusive_scan(InputIterator first, InputIterator last, - OutputIterator result, - BinaryOperation binary_op, UnaryOperation unary_op, - T init); // C++17 - -template - OutputIterator - adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); - -template - OutputIterator - adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); -#endif // __cuda_std__ - -template - void iota(ForwardIterator first, ForwardIterator last, T value); - -#ifndef __cuda_std__ -template - constexpr common_type_t gcd(M m, N n); // C++17 - -template - constexpr common_type_t lcm(M m, N n); // C++17 -#endif // __cuda_std__ - -integer midpoint(integer a, integer b); // C++20 -pointer midpoint(pointer a, pointer b); // C++20 -floating_point midpoint(floating_point a, floating_point b); // C++20 - -} // std - -*/ - -#include - -#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 - -#include // all public C++ headers provide the assertion handler -#include -#include -#include // for isnormal -#include -#include // for numeric_limits -#include - -#include - -_LIBCUDACXX_BEGIN_NAMESPACE_STD - -#ifndef __cuda_std__ -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) -{ - for (; __first != __last; ++__first) - __init = __init + *__first; - return __init; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) -{ - for (; __first != __last; ++__first) - __init = __binary_op(__init, *__first); - return __init; -} - -#if _CCCL_STD_VER > 2014 -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) -{ - for (; __first != __last; ++__first) - __init = __b(__init, *__first); - return __init; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -reduce(_InputIterator __first, _InputIterator __last, _Tp __init) -{ - return _CUDA_VSTD::reduce(__first, __last, __init, _CUDA_VSTD::plus<>()); -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -typename iterator_traits<_InputIterator>::value_type -reduce(_InputIterator __first, _InputIterator __last) -{ - return _CUDA_VSTD::reduce(__first, __last, - typename iterator_traits<_InputIterator>::value_type{}); -} -#endif - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) -{ - for (; __first1 != __last1; ++__first1, (void) ++__first2) - __init = __init + *__first1 * *__first2; - return __init; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, - _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2) -{ - for (; __first1 != __last1; ++__first1, (void) ++__first2) - __init = __binary_op1(__init, __binary_op2(*__first1, *__first2)); - return __init; -} - -#if _CCCL_STD_VER > 2014 -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -transform_reduce(_InputIterator __first, _InputIterator __last, - _Tp __init, _BinaryOp __b, _UnaryOp __u) -{ - for (; __first != __last; ++__first) - __init = __b(__init, __u(*__first)); - return __init; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2) -{ - for (; __first1 != __last1; ++__first1, (void) ++__first2) - __init = __b1(__init, __b2(*__first1, *__first2)); - return __init; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp -transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _Tp __init) -{ - return _CUDA_VSTD::transform_reduce(__first1, __last1, __first2, _CUDA_VSTD::move(__init), - _CUDA_VSTD::plus<>(), _CUDA_VSTD::multiplies<>()); -} -#endif - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_OutputIterator -partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) -{ - if (__first != __last) - { - typename iterator_traits<_InputIterator>::value_type __t(*__first); - *__result = __t; - for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) - { - __t = __t + *__first; - *__result = __t; - } - } - return __result; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_OutputIterator -partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, - _BinaryOperation __binary_op) -{ - if (__first != __last) - { - typename iterator_traits<_InputIterator>::value_type __t(*__first); - *__result = __t; - for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) - { - __t = __binary_op(__t, *__first); - *__result = __t; - } - } - return __result; -} - -#if _CCCL_STD_VER > 2014 -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_OutputIterator -exclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _Tp __init, _BinaryOp __b) -{ - if (__first != __last) - { - _Tp __saved = __init; - do - { - __init = __b(__init, *__first); - *__result = __saved; - __saved = __init; - ++__result; - } while (++__first != __last); - } - return __result; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_OutputIterator -exclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _Tp __init) -{ - return _CUDA_VSTD::exclusive_scan(__first, __last, __result, __init, _CUDA_VSTD::plus<>()); -} - -template -_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _BinaryOp __b, _Tp __init) -{ - for (; __first != __last; ++__first, (void) ++__result) { - __init = __b(__init, *__first); - *__result = __init; - } - return __result; -} - -template -_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _BinaryOp __b) -{ - if (__first != __last) { - typename std::iterator_traits<_InputIterator>::value_type __init = *__first; - *__result++ = __init; - if (++__first != __last) - return _CUDA_VSTD::inclusive_scan(__first, __last, __result, __b, __init); - } - - return __result; -} - -template -_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result) -{ - return _CUDA_VSTD::inclusive_scan(__first, __last, __result, std::plus<>()); -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_OutputIterator -transform_exclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _Tp __init, - _BinaryOp __b, _UnaryOp __u) -{ - if (__first != __last) - { - _Tp __saved = __init; - do - { - __init = __b(__init, __u(*__first)); - *__result = __saved; - __saved = __init; - ++__result; - } while (++__first != __last); - } - return __result; -} - -template -_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init) -{ - for (; __first != __last; ++__first, (void) ++__result) { - __init = __b(__init, __u(*__first)); - *__result = __init; - } - - return __result; -} - -template -_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _BinaryOp __b, _UnaryOp __u) -{ - if (__first != __last) { - typename std::iterator_traits<_InputIterator>::value_type __init = __u(*__first); - *__result++ = __init; - if (++__first != __last) - return _CUDA_VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init); - } - - return __result; -} -#endif - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_OutputIterator -adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) -{ - if (__first != __last) - { - typename iterator_traits<_InputIterator>::value_type __t1(*__first); - *__result = __t1; - for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) - { - typename iterator_traits<_InputIterator>::value_type __t2(*__first); - *__result = __t2 - __t1; - __t1 = _CUDA_VSTD::move(__t2); - } - } - return __result; -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_OutputIterator -adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, - _BinaryOperation __binary_op) -{ - if (__first != __last) - { - typename iterator_traits<_InputIterator>::value_type __t1(*__first); - *__result = __t1; - for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) - { - typename iterator_traits<_InputIterator>::value_type __t2(*__first); - *__result = __binary_op(__t2, __t1); - __t1 = _CUDA_VSTD::move(__t2); - } - } - return __result; -} -#endif // __cuda_std__ - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) -{ - for (; __first != __last; ++__first, (void) ++__value_) - *__first = __value_; -} - - -#ifndef __cuda_std__ -#if _CCCL_STD_VER > 2014 -template ::value> struct __ct_abs; - -template -struct __ct_abs<_Result, _Source, true> { - constexpr _LIBCUDACXX_INLINE_VISIBILITY - _Result operator()(_Source __t) const noexcept - { - if (__t >= 0) return __t; - if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t); - return -__t; - } -}; - -template -struct __ct_abs<_Result, _Source, false> { - constexpr _LIBCUDACXX_INLINE_VISIBILITY - _Result operator()(_Source __t) const noexcept { return __t; } -}; - - -template -constexpr _LIBCUDACXX_HIDDEN -_Tp __gcd(_Tp __m, _Tp __n) -{ - static_assert((!is_signed<_Tp>::value), ""); - return __n == 0 ? __m : _CUDA_VSTD::__gcd<_Tp>(__n, __m % __n); -} - - -template -constexpr _LIBCUDACXX_INLINE_VISIBILITY -common_type_t<_Tp,_Up> -gcd(_Tp __m, _Up __n) -{ - static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types"); - static_assert((!is_same<__remove_cv_t<_Tp>, bool>::value), "First argument to gcd cannot be bool" ); - static_assert((!is_same<__remove_cv_t<_Up>, bool>::value), "Second argument to gcd cannot be bool" ); - using _Rp = common_type_t<_Tp,_Up>; - using _Wp = make_unsigned_t<_Rp>; - return static_cast<_Rp>(_CUDA_VSTD::__gcd( - static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)), - static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n)))); -} - -template -constexpr _LIBCUDACXX_INLINE_VISIBILITY -common_type_t<_Tp,_Up> -lcm(_Tp __m, _Up __n) -{ - static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types"); - static_assert((!is_same<__remove_cv_t<_Tp>, bool>::value), "First argument to lcm cannot be bool" ); - static_assert((!is_same<__remove_cv_t<_Up>, bool>::value), "Second argument to lcm cannot be bool" ); - if (__m == 0 || __n == 0) - return 0; - - using _Rp = common_type_t<_Tp,_Up>; - _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _CUDA_VSTD::gcd(__m, __n); - _Rp __val2 = __ct_abs<_Rp, _Up>()(__n); - _LIBCUDACXX_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); - return __val1 * __val2; -} - -#endif /* _CCCL_STD_VER > 2014 */ - -#if _CCCL_STD_VER > 2017 -template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -enable_if_t && !is_same_v && !is_null_pointer_v<_Tp>, _Tp> -midpoint(_Tp __a, _Tp __b) noexcept -_LIBCUDACXX_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK -{ - using _Up = std::make_unsigned_t<_Tp>; - - int __sign = 1; - _Up __m = __a; - _Up __M = __b; - if (__a > __b) - { - __sign = -1; - __m = __b; - __M = __a; - } - return __a + __sign * _Tp(_Up(__M-__m) >> 1); -} - - -template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -enable_if_t - && is_object_v> - && ! is_void_v> - && (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr> -midpoint(_TPtr __a, _TPtr __b) noexcept -{ - return __a + _CUDA_VSTD::midpoint(ptrdiff_t(0), __b - __a); -} - - -template -constexpr int __sign(_Tp __val) { - return (_Tp(0) < __val) - (__val < _Tp(0)); -} - -template -constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; } - -template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -enable_if_t, _Fp> -midpoint(_Fp __a, _Fp __b) noexcept -{ - constexpr _Fp __lo = numeric_limits<_Fp>::min()*2; - constexpr _Fp __hi = numeric_limits<_Fp>::max()/2; - return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ? // typical case: overflow is impossible - (__a + __b)/2 : // always correctly rounded - __fp_abs(__a) < __lo ? __a + __b/2 : // not safe to halve a - __fp_abs(__a) < __lo ? __a/2 + __b : // not safe to halve b - __a/2 + __b/2; // otherwise correctly rounded -} - -#endif // _CCCL_STD_VER > 2017 -#endif // __cuda_std__ - -_LIBCUDACXX_END_NAMESPACE_STD - -#if defined(_LIBCUDACXX_HAS_PARALLEL_ALGORITHMS) && _CCCL_STD_VER >= 2017 -# include <__pstl_numeric> -#endif - -#include //__cuda_std__ - -#endif // _LIBCUDACXX_NUMERIC diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/optional b/libcudacxx/include/cuda/std/detail/libcxx/include/optional index b4940773eae..79da420c0cc 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/optional +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/optional @@ -169,8 +169,6 @@ template # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler -#include #include #include #include @@ -183,12 +181,12 @@ template #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -196,17 +194,19 @@ template #include #include #include +#include // all public C++ headers provide the assertion handler +#include #include #include #include #include -#include // standard-mandated includes +#include // [optional.syn] #ifndef _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR -#include +# include #endif // !_LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR #include @@ -240,13 +240,17 @@ _CCCL_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY void __throw_bad_optional_ac struct nullopt_t { - struct __secret_tag { explicit __secret_tag() = default; }; - _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} + struct __secret_tag + { + explicit __secret_tag() = default; + }; + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {} }; _LIBCUDACXX_CPO_ACCESSIBILITY nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}}; -struct __optional_construct_from_invoke_tag {}; +struct __optional_construct_from_invoke_tag +{}; template ::value> struct __optional_destruct_base; @@ -254,339 +258,334 @@ struct __optional_destruct_base; template struct __optional_destruct_base<_Tp, false> { - typedef _Tp value_type; - static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), - "instantiation of optional with a non-object type is undefined behavior"); - union - { - char __null_state_; - __remove_cv_t __val_; - }; - bool __engaged_; - - _CCCL_EXEC_CHECK_DISABLE - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX20 ~__optional_destruct_base() + typedef _Tp value_type; + static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + __remove_cv_t __val_; + }; + bool __engaged_; + + _CCCL_EXEC_CHECK_DISABLE + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX20 ~__optional_destruct_base() + { + if (__engaged_) { - if (__engaged_) - __val_.~value_type(); + __val_.~value_type(); } + } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base() noexcept - : __null_state_(), - __engaged_(false) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) - : __val_(_CUDA_VSTD::forward<_Args>(__args)...), - __engaged_(true) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) - : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)), __engaged_(true) {} - - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX20 void reset() noexcept + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept + : __null_state_() + , __engaged_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_CUDA_VSTD::forward<_Args>(__args)...) + , __engaged_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)) + , __engaged_(true) + {} + + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX20 void reset() noexcept + { + if (__engaged_) { - if (__engaged_) - { - __val_.~value_type(); - __engaged_ = false; - } + __val_.~value_type(); + __engaged_ = false; } + } }; template struct __optional_destruct_base<_Tp, true> { - typedef _Tp value_type; - static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), - "instantiation of optional with a non-object type is undefined behavior"); - union - { - char __null_state_; - __remove_cv_t __val_; - }; - bool __engaged_; - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base() noexcept - : __null_state_(), - __engaged_(false) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) - : __val_(_CUDA_VSTD::forward<_Args>(__args)...), - __engaged_(true) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_destruct_base(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) - : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)), __engaged_(true) {} - - _LIBCUDACXX_INLINE_VISIBILITY - constexpr void reset() noexcept + typedef _Tp value_type; + static_assert(_LIBCUDACXX_TRAIT(is_object, value_type), + "instantiation of optional with a non-object type is undefined behavior"); + union + { + char __null_state_; + __remove_cv_t __val_; + }; + bool __engaged_; + + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base() noexcept + : __null_state_() + , __engaged_(false) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args) + : __val_(_CUDA_VSTD::forward<_Args>(__args)...) + , __engaged_(true) + {} + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_destruct_base( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __val_(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...)) + , __engaged_(true) + {} + + _LIBCUDACXX_INLINE_VISIBILITY constexpr void reset() noexcept + { + if (__engaged_) { - if (__engaged_) - { - __engaged_ = false; - } + __engaged_ = false; } + } }; template struct __optional_storage_base : __optional_destruct_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_storage_base, __optional_destruct_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_storage_base, __optional_destruct_base, _Tp); - using value_type = _Tp; + using value_type = _Tp; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr bool has_value() const noexcept - { - return this->__engaged_; - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr bool has_value() const noexcept + { + return this->__engaged_; + } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr value_type& __get() & noexcept - { - return this->__val_; - } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr const value_type& __get() const& noexcept - { - return this->__val_; - } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr value_type&& __get() && noexcept - { - return _CUDA_VSTD::move(this->__val_); - } - _LIBCUDACXX_INLINE_VISIBILITY - constexpr const value_type&& __get() const&& noexcept - { - return _CUDA_VSTD::move(this->__val_); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type& __get() & noexcept + { + return this->__val_; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type& __get() const& noexcept + { + return this->__val_; + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type&& __get() && noexcept + { + return _CUDA_VSTD::move(this->__val_); + } + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type&& __get() const&& noexcept + { + return _CUDA_VSTD::move(this->__val_); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX20 void __construct(_Args&&... __args) + { + _LIBCUDACXX_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); +# if _CCCL_STD_VER > 2017 + _CUDA_VSTD::construct_at(_CUDA_VSTD::addressof(this->__val_), _CUDA_VSTD::forward<_Args>(__args)...); +# else + ::new ((void*) _CUDA_VSTD::addressof(this->__val_)) value_type(_CUDA_VSTD::forward<_Args>(__args)...); +# endif + this->__engaged_ = true; + } - template - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX20 void __construct(_Args&&... __args) + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr void __construct_from(_That&& __opt) + { + if (__opt.has_value()) { - _LIBCUDACXX_ASSERT(!has_value(), "__construct called for engaged __optional_storage"); -#if _CCCL_STD_VER > 2017 - _CUDA_VSTD::construct_at(_CUDA_VSTD::addressof(this->__val_), _CUDA_VSTD::forward<_Args>(__args)...); -#else - ::new ((void*)_CUDA_VSTD::addressof(this->__val_)) value_type(_CUDA_VSTD::forward<_Args>(__args)...); -#endif - this->__engaged_ = true; + __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); } + } - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr void __construct_from(_That&& __opt) + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr void __assign_from(_That&& __opt) + { + if (this->__engaged_ == __opt.has_value()) { - if (__opt.has_value()) - __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); + if (this->__engaged_) + { + this->__val_ = _CUDA_VSTD::forward<_That>(__opt).__get(); + } } - - template - _LIBCUDACXX_INLINE_VISIBILITY - constexpr void __assign_from(_That&& __opt) + else { - if (this->__engaged_ == __opt.has_value()) - { - if (this->__engaged_) - this->__val_ = _CUDA_VSTD::forward<_That>(__opt).__get(); - } - else - { - if (this->__engaged_) - this->reset(); - else - __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); - } + if (this->__engaged_) + { + this->reset(); + } + else + { + __construct(_CUDA_VSTD::forward<_That>(__opt).__get()); + } } + } }; template ::value> struct __optional_copy_base : __optional_storage_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); }; template struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_base, __optional_storage_base, _Tp); - // This ctor shouldn't need to initialize the base explicitly, but g++ 9 considers it to be uninitialized - // during constexpr evaluation if it isn't initialized explicitly. This can be replaced with the pattern - // below, in __optional_move_base, once g++ 9 falls off our support matrix. - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_copy_base(const __optional_copy_base& __opt) : __base() - { - this->__construct_from(__opt); - } + // This ctor shouldn't need to initialize the base explicitly, but g++ 9 considers it to be uninitialized + // during constexpr evaluation if it isn't initialized explicitly. This can be replaced with the pattern + // below, in __optional_move_base, once g++ 9 falls off our support matrix. + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_copy_base(const __optional_copy_base& __opt) + : __base() + { + this->__construct_from(__opt); + } - __optional_copy_base(__optional_copy_base&&) = default; - __optional_copy_base& operator=(const __optional_copy_base&) = default; - __optional_copy_base& operator=(__optional_copy_base&&) = default; + __optional_copy_base(__optional_copy_base&&) = default; + __optional_copy_base& operator=(const __optional_copy_base&) = default; + __optional_copy_base& operator=(__optional_copy_base&&) = default; }; template ::value> struct __optional_move_base : __optional_copy_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); }; template struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_base, __optional_copy_base, _Tp); - __optional_move_base(const __optional_move_base&) = default; + __optional_move_base(const __optional_move_base&) = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_move_base(__optional_move_base&& __opt) - noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) - { - this->__construct_from(_CUDA_VSTD::move(__opt)); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_move_base(__optional_move_base&& __opt) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) + { + this->__construct_from(_CUDA_VSTD::move(__opt)); + } - __optional_move_base& operator=(const __optional_move_base&) = default; - __optional_move_base& operator=(__optional_move_base&&) = default; + __optional_move_base& operator=(const __optional_move_base&) = default; + __optional_move_base& operator=(__optional_move_base&&) = default; }; -template ::value && - is_trivially_copy_constructible<_Tp>::value && - is_trivially_copy_assignable<_Tp>::value> +template ::value && is_trivially_copy_constructible<_Tp>::value + && is_trivially_copy_assignable<_Tp>::value> struct __optional_copy_assign_base : __optional_move_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); }; template struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_copy_assign_base, __optional_move_base, _Tp); - __optional_copy_assign_base(const __optional_copy_assign_base&) = default; - __optional_copy_assign_base(__optional_copy_assign_base&&) = default; + __optional_copy_assign_base(const __optional_copy_assign_base&) = default; + __optional_copy_assign_base(__optional_copy_assign_base&&) = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_copy_assign_base& operator=(const __optional_copy_assign_base& __opt) - { - this->__assign_from(__opt); - return *this; - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_copy_assign_base& + operator=(const __optional_copy_assign_base& __opt) + { + this->__assign_from(__opt); + return *this; + } - __optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default; + __optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default; }; -template ::value && - is_trivially_move_constructible<_Tp>::value && - is_trivially_move_assignable<_Tp>::value> +template ::value && is_trivially_move_constructible<_Tp>::value + && is_trivially_move_assignable<_Tp>::value> struct __optional_move_assign_base : __optional_copy_assign_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); }; template struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp> { - _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); + _LIBCUDACXX_DELEGATE_CONSTRUCTORS(__optional_move_assign_base, __optional_copy_assign_base, _Tp); - __optional_move_assign_base(const __optional_move_assign_base& __opt) = default; - __optional_move_assign_base(__optional_move_assign_base&&) = default; - __optional_move_assign_base& operator=(const __optional_move_assign_base&) = default; + __optional_move_assign_base(const __optional_move_assign_base& __opt) = default; + __optional_move_assign_base(__optional_move_assign_base&&) = default; + __optional_move_assign_base& operator=(const __optional_move_assign_base&) = default; - _LIBCUDACXX_INLINE_VISIBILITY - constexpr __optional_move_assign_base& operator=(__optional_move_assign_base&& __opt) - noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp) && - _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) - { - this->__assign_from(_CUDA_VSTD::move(__opt)); - return *this; - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr __optional_move_assign_base& + operator=(__optional_move_assign_base&& __opt) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp) && _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, _Tp)) + { + this->__assign_from(_CUDA_VSTD::move(__opt)); + return *this; + } }; template -using __optional_sfinae_ctor_base_t = __sfinae_ctor_base< - is_copy_constructible<_Tp>::value, - is_move_constructible<_Tp>::value ->; +using __optional_sfinae_ctor_base_t = + __sfinae_ctor_base::value, is_move_constructible<_Tp>::value>; template -using __optional_sfinae_assign_base_t = __sfinae_assign_base< - (is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), - (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) ->; +using __optional_sfinae_assign_base_t = + __sfinae_assign_base<(is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value), + (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)>; -template +template class optional; template -struct __is_std_optional : false_type {}; -template +struct __is_std_optional : false_type +{}; +template struct __is_std_optional> : true_type -{ -}; +{}; // Constraits template > -using __opt_check_constructible_from_opt = _Or< - is_constructible<_Tp, _Opt&>, - is_constructible<_Tp, _Opt const&>, - is_constructible<_Tp, _Opt&&>, - is_constructible<_Tp, _Opt const&&>, - is_convertible<_Opt&, _Tp>, - is_convertible<_Opt const&, _Tp>, - is_convertible<_Opt&&, _Tp>, - is_convertible<_Opt const&&, _Tp> ->; +using __opt_check_constructible_from_opt = + _Or, + is_constructible<_Tp, _Opt const&>, + is_constructible<_Tp, _Opt&&>, + is_constructible<_Tp, _Opt const&&>, + is_convertible<_Opt&, _Tp>, + is_convertible<_Opt const&, _Tp>, + is_convertible<_Opt&&, _Tp>, + is_convertible<_Opt const&&, _Tp>>; template > -using __opt_check_assignable_from_opt = _Or< - is_assignable<_Tp&, _Opt&>, - is_assignable<_Tp&, _Opt const&>, - is_assignable<_Tp&, _Opt&&>, - is_assignable<_Tp&, _Opt const&&> ->; - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_implictly_constructible = _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) - && _LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_explictly_constructible = _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) - && !_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_U = !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, in_place_t) - && !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_opt = !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) - && !__opt_check_constructible_from_opt<_Tp, _Up>::value; - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable = _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) - && _LIBCUDACXX_TRAIT(is_assignable, _Tp&, _Up); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_U = !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>) - && (!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, _Tp) - || !_LIBCUDACXX_TRAIT(is_scalar, _Tp)); - -template -_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_opt = !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) - && !__opt_check_constructible_from_opt<_Tp, _Up>::value - && !__opt_check_assignable_from_opt<_Tp, _Up>::value; +using __opt_check_assignable_from_opt = + _Or, + is_assignable<_Tp&, _Opt const&>, + is_assignable<_Tp&, _Opt&&>, + is_assignable<_Tp&, _Opt const&&>>; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_implictly_constructible = + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) && _LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_explictly_constructible = + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) && !_LIBCUDACXX_TRAIT(is_convertible, _Up, _Tp); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_U = + !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, in_place_t) + && !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_constructible_from_opt = + !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) && !__opt_check_constructible_from_opt<_Tp, _Up>::value; + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable = + _LIBCUDACXX_TRAIT(is_constructible, _Tp, _Up) && _LIBCUDACXX_TRAIT(is_assignable, _Tp&, _Up); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_U = + !_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, optional<_Tp>) + && (!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t<_Up>, _Tp) || !_LIBCUDACXX_TRAIT(is_scalar, _Tp)); + +template +_LIBCUDACXX_INLINE_VAR constexpr bool __opt_is_assignable_from_opt = + !_LIBCUDACXX_TRAIT(is_same, _Up, _Tp) && !__opt_check_constructible_from_opt<_Tp, _Up>::value + && !__opt_check_assignable_from_opt<_Tp, _Up>::value; template class optional @@ -594,830 +593,772 @@ class optional , private __optional_sfinae_ctor_base_t<_Tp> , private __optional_sfinae_assign_base_t<_Tp> { - using __base = __optional_move_assign_base<_Tp>; + using __base = __optional_move_assign_base<_Tp>; - template - friend class optional; + template + friend class optional; public: - using value_type = _Tp; + using value_type = _Tp; private: - // Disable the reference extension using this static assert. - static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, in_place_t), - "instantiation of optional with in_place_t is ill-formed"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, nullopt_t), - "instantiation of optional with nullopt_t is ill-formed"); - static_assert(!_LIBCUDACXX_TRAIT(is_reference, value_type), - "instantiation of optional with a reference type is ill-formed"); - static_assert(_LIBCUDACXX_TRAIT(is_destructible, value_type), - "instantiation of optional with a non-destructible type is ill-formed"); - static_assert(!_LIBCUDACXX_TRAIT(is_array, value_type), - "instantiation of optional with an array type is ill-formed"); + // Disable the reference extension using this static assert. + static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, in_place_t), + "instantiation of optional with in_place_t is ill-formed"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, __remove_cvref_t, nullopt_t), + "instantiation of optional with nullopt_t is ill-formed"); + static_assert(!_LIBCUDACXX_TRAIT(is_reference, value_type), + "instantiation of optional with a reference type is ill-formed"); + static_assert(_LIBCUDACXX_TRAIT(is_destructible, value_type), + "instantiation of optional with a non-destructible type is ill-formed"); + static_assert(!_LIBCUDACXX_TRAIT(is_array, value_type), "instantiation of optional with an array type is ill-formed"); public: + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional() noexcept {} + constexpr optional(const optional&) = default; + constexpr optional(optional&&) = default; + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} + + _LIBCUDACXX_TEMPLATE(class _In_place_t, class... _Args) + _LIBCUDACXX_REQUIRES(_LIBCUDACXX_TRAIT(is_same, _In_place_t, in_place_t) + _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_constructible, value_type, _Args...)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(_In_place_t, _Args&&... __args) + : __base(in_place, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) + _LIBCUDACXX_REQUIRES(_LIBCUDACXX_TRAIT(is_constructible, value_type, initializer_list<_Up>&, _Args...)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) + : __base(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...) + {} + + _LIBCUDACXX_TEMPLATE(class _Up = value_type) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND __opt_is_implictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(_Up&& __v) + : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) + {} + + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND __opt_is_explictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(_Up&& __v) + : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) + {} + + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_implictly_constructible<_Tp, const _Up&>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr optional() noexcept {} - constexpr optional(const optional&) = default; - constexpr optional(optional&&) = default; - _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} - - _LIBCUDACXX_TEMPLATE(class _In_place_t, class... _Args) - _LIBCUDACXX_REQUIRES( _LIBCUDACXX_TRAIT(is_same, _In_place_t, in_place_t) _LIBCUDACXX_AND - _LIBCUDACXX_TRAIT(is_constructible, value_type, _Args...)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(_In_place_t, _Args&&... __args) - : __base(in_place, _CUDA_VSTD::forward<_Args>(__args)...) {} - - _LIBCUDACXX_TEMPLATE(class _Up, class... _Args) - _LIBCUDACXX_REQUIRES( _LIBCUDACXX_TRAIT(is_constructible, value_type, initializer_list<_Up>&, _Args...)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) - : __base(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...) {} - - _LIBCUDACXX_TEMPLATE(class _Up = value_type) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_implictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional(_Up&& __v) : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) {} - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_U<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_explictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(_Up&& __v) : __base(in_place, _CUDA_VSTD::forward<_Up>(__v)) {} - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_implictly_constructible<_Tp, const _Up&>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional(const optional<_Up>& __v) { - this->__construct_from(__v); - } - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_explictly_constructible<_Tp, const _Up&>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(const optional<_Up>& __v) { - this->__construct_from(__v); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_explictly_constructible<_Tp, const _Up&>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(const optional<_Up>& __v) + { + this->__construct_from(__v); + } - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_implictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional(optional<_Up>&& __v) { - this->__construct_from(_CUDA_VSTD::move(__v)); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_implictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional(optional<_Up>&& __v) + { + this->__construct_from(_CUDA_VSTD::move(__v)); + } - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_explictly_constructible<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(optional<_Up>&& __v) { - this->__construct_from(_CUDA_VSTD::move(__v)); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES( + __opt_is_constructible_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_explictly_constructible<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional(optional<_Up>&& __v) + { + this->__construct_from(_CUDA_VSTD::move(__v)); + } private: - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit optional(__optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) - : __base(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...) { - } + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit optional( + __optional_construct_from_invoke_tag, _Fp&& __f, _Args&&... __args) + : __base( + __optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_Args>(__args)...) + {} public: + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(nullopt_t) noexcept + { + reset(); + return *this; + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(nullopt_t) noexcept { - reset(); - return *this; - } + constexpr optional& operator=(const optional&) = default; + constexpr optional& operator=(optional&&) = default; - constexpr optional& operator=(const optional&) = default; - constexpr optional& operator=(optional&&) = default; - - _LIBCUDACXX_TEMPLATE(class _Up = value_type) - _LIBCUDACXX_REQUIRES( __opt_is_assignable_from_U<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_assignable<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(_Up&& __v) { - if (this->has_value()) - this->__get() = _CUDA_VSTD::forward<_Up>(__v); - else - this->__construct(_CUDA_VSTD::forward<_Up>(__v)); - return *this; + _LIBCUDACXX_TEMPLATE(class _Up = value_type) + _LIBCUDACXX_REQUIRES(__opt_is_assignable_from_U<_Tp, _Up> _LIBCUDACXX_AND __opt_is_assignable<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(_Up&& __v) + { + if (this->has_value()) + { + this->__get() = _CUDA_VSTD::forward<_Up>(__v); } - - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_assignable<_Tp, const _Up&>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(const optional<_Up>& __v) { - this->__assign_from(__v); - return *this; + else + { + this->__construct(_CUDA_VSTD::forward<_Up>(__v)); } + return *this; + } - _LIBCUDACXX_TEMPLATE(class _Up) - _LIBCUDACXX_REQUIRES( __opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND - __opt_is_assignable<_Tp, _Up>) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional& operator=(optional<_Up>&& __v) { - this->__assign_from(_CUDA_VSTD::move(__v)); - return *this; - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES(__opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_assignable<_Tp, const _Up&>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(const optional<_Up>& __v) + { + this->__assign_from(__v); + return *this; + } - template = 0> - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _Tp& emplace(_Args&&... __args) { - reset(); - this->__construct(_CUDA_VSTD::forward<_Args>(__args)...); - return this->__get(); - } + _LIBCUDACXX_TEMPLATE(class _Up) + _LIBCUDACXX_REQUIRES(__opt_is_assignable_from_opt<_Tp, _Up> _LIBCUDACXX_AND __opt_is_assignable<_Tp, _Up>) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional& operator=(optional<_Up>&& __v) + { + this->__assign_from(_CUDA_VSTD::move(__v)); + return *this; + } - template&, _Args...), int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY constexpr - _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { - reset(); - this->__construct(__il, _CUDA_VSTD::forward<_Args>(__args)...); - return this->__get(); - } + template = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp& emplace(_Args&&... __args) + { + reset(); + this->__construct(_CUDA_VSTD::forward<_Args>(__args)...); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - void swap(optional& __opt) - noexcept(_LIBCUDACXX_TRAIT(is_nothrow_move_constructible, value_type) && - _LIBCUDACXX_TRAIT(is_nothrow_swappable, value_type)) - { - if (this->has_value() == __opt.has_value()) - { - using _CUDA_VSTD::swap; - if (this->has_value()) - swap(this->__get(), __opt.__get()); - } - else - { - if (this->has_value()) - { - __opt.__construct(_CUDA_VSTD::move(this->__get())); - reset(); - } - else - { - this->__construct(_CUDA_VSTD::move(__opt.__get())); - __opt.reset(); - } - } - } + template &, _Args...), int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) + { + reset(); + this->__construct(__il, _CUDA_VSTD::forward<_Args>(__args)...); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - add_pointer_t operator->() const + _LIBCUDACXX_INLINE_VISIBILITY constexpr void swap(optional& __opt) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_move_constructible, value_type) && _LIBCUDACXX_TRAIT(is_nothrow_swappable, value_type)) + { + if (this->has_value() == __opt.has_value()) { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); - return _CUDA_VSTD::addressof(this->__get()); + using _CUDA_VSTD::swap; + if (this->has_value()) + { + swap(this->__get(), __opt.__get()); + } } - - _LIBCUDACXX_INLINE_VISIBILITY constexpr - add_pointer_t operator->() + else { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); - return _CUDA_VSTD::addressof(this->__get()); + if (this->has_value()) + { + __opt.__construct(_CUDA_VSTD::move(this->__get())); + reset(); + } + else + { + this->__construct(_CUDA_VSTD::move(__opt.__get())); + __opt.reset(); + } } + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - const value_type& operator*() const& noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return this->__get(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr add_pointer_t operator->() const + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); + return _CUDA_VSTD::addressof(this->__get()); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type& operator*() & noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return this->__get(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr add_pointer_t operator->() + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator-> called on a disengaged value"); + return _CUDA_VSTD::addressof(this->__get()); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type&& operator*() && noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return _CUDA_VSTD::move(this->__get()); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type& operator*() const& noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - const value_type&& operator*() const&& noexcept - { - _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); - return _CUDA_VSTD::move(this->__get()); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type& operator*() & noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit operator bool() const noexcept { return has_value(); } + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type&& operator*() && noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return _CUDA_VSTD::move(this->__get()); + } - using __base::has_value; - using __base::__get; + _LIBCUDACXX_INLINE_VISIBILITY constexpr const value_type&& operator*() const&& noexcept + { + _LIBCUDACXX_ASSERT(this->has_value(), "optional operator* called on a disengaged value"); + return _CUDA_VSTD::move(this->__get()); + } - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type const& value() const& - { - if (!this->has_value()) - __throw_bad_optional_access(); - return this->__get(); - } + _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit operator bool() const noexcept + { + return has_value(); + } - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type& value() & + using __base::__get; + using __base::has_value; + + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type const& + value() const& + { + if (!this->has_value()) { - if (!this->has_value()) - __throw_bad_optional_access(); - return this->__get(); + __throw_bad_optional_access(); } + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type&& value() && + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type& value() & + { + if (!this->has_value()) { - if (!this->has_value()) - __throw_bad_optional_access(); - return _CUDA_VSTD::move(this->__get()); + __throw_bad_optional_access(); } + return this->__get(); + } - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - value_type const&& value() const&& + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type&& value() && + { + if (!this->has_value()) { - if (!this->has_value()) - __throw_bad_optional_access(); - return _CUDA_VSTD::move(this->__get()); + __throw_bad_optional_access(); } + return _CUDA_VSTD::move(this->__get()); + } - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type value_or(_Up&& __v) const& + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr value_type const&& + value() const&& + { + if (!this->has_value()) { - static_assert(_LIBCUDACXX_TRAIT(is_copy_constructible, value_type), - "optional::value_or: T must be copy constructible"); - static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), - "optional::value_or: U must be convertible to T"); - return this->has_value() ? this->__get() : - static_cast(_CUDA_VSTD::forward<_Up>(__v)); + __throw_bad_optional_access(); } + return _CUDA_VSTD::move(this->__get()); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type value_or(_Up&& __v) const& + { + static_assert(_LIBCUDACXX_TRAIT(is_copy_constructible, value_type), + "optional::value_or: T must be copy constructible"); + static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), + "optional::value_or: U must be convertible to T"); + return this->has_value() ? this->__get() : static_cast(_CUDA_VSTD::forward<_Up>(__v)); + } - template - _LIBCUDACXX_INLINE_VISIBILITY constexpr - value_type value_or(_Up&& __v) && + template + _LIBCUDACXX_INLINE_VISIBILITY constexpr value_type value_or(_Up&& __v) && + { + static_assert(_LIBCUDACXX_TRAIT(is_move_constructible, value_type), + "optional::value_or: T must be move constructible"); + static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), + "optional::value_or: U must be convertible to T"); + return this->has_value() ? _CUDA_VSTD::move(this->__get()) : static_cast(_CUDA_VSTD::forward<_Up>(__v)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto and_then(_Func&& __f) & + { + using _Up = invoke_result_t<_Func, value_type&>; + static_assert(__is_std_optional>::value, + "Result of f(value()) must be a specialization of std::optional"); + if (this->__engaged_) { - static_assert(_LIBCUDACXX_TRAIT(is_move_constructible, value_type), - "optional::value_or: T must be move constructible"); - static_assert(_LIBCUDACXX_TRAIT(is_convertible, _Up, value_type), - "optional::value_or: U must be convertible to T"); - return this->has_value() ? _CUDA_VSTD::move(this->__get()) : - static_cast(_CUDA_VSTD::forward<_Up>(__v)); + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) & { - using _Up = invoke_result_t<_Func, value_type&>; - static_assert(__is_std_optional>::value, - "Result of f(value()) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return remove_cvref_t<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + and_then(_Func&& __f) const& + { + using _Up = invoke_result_t<_Func, const value_type&>; + static_assert(__is_std_optional>::value, + "Result of f(value()) must be a specialization of std::optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) const& { - using _Up = invoke_result_t<_Func, const value_type&>; - static_assert(__is_std_optional>::value, - "Result of f(value()) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return remove_cvref_t<_Up>(); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) && { - using _Up = invoke_result_t<_Func, value_type&&>; - static_assert(__is_std_optional>::value, - "Result of f(std::move(value())) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return remove_cvref_t<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + and_then(_Func&& __f) && + { + using _Up = invoke_result_t<_Func, value_type&&>; + static_assert(__is_std_optional>::value, + "Result of f(std::move(value())) must be a specialization of std::optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto and_then(_Func&& __f) const&& { - using _Up = invoke_result_t<_Func, const value_type&&>; - static_assert(__is_std_optional>::value, - "Result of f(std::move(value())) must be a specialization of std::optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return remove_cvref_t<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + and_then(_Func&& __f) const&& + { + using _Up = invoke_result_t<_Func, const value_type&&>; + static_assert(__is_std_optional>::value, + "Result of f(std::move(value())) must be a specialization of std::optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return remove_cvref_t<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) & { - using _Up = remove_cv_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(value()) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(value()) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) & + { + using _Up = remove_cv_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), "Result of f(value()) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), "Result of f(value()) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return optional<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) const& { - using _Up = remove_cv_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(value()) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(value()) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) const& + { + using _Up = remove_cv_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(value()) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), "Result of f(value()) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), "Result of f(value()) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(value()) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), this->__get()); } + return optional<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) && { - using _Up = remove_cv_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(std::move(value())) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(std::move(value())) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) && + { + using _Up = remove_cv_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), + "Result of f(std::move(value())) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), + "Result of f(std::move(value())) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>( + __optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return optional<_Up>(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr - auto transform(_Func&& __f) const&& { - using _Up = remove_cvref_t>; - static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), - "Result of f(std::move(value())) should not be std::in_place_t"); - static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), - "Result of f(std::move(value())) should not be std::nullopt_t"); - static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); - if (this->__engaged_) - { - return optional<_Up>(__optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); - } - return optional<_Up>(); + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS constexpr auto + transform(_Func&& __f) const&& + { + using _Up = remove_cvref_t>; + static_assert(!_LIBCUDACXX_TRAIT(is_array, _Up), "Result of f(std::move(value())) should not be an Array"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, in_place_t), + "Result of f(std::move(value())) should not be std::in_place_t"); + static_assert(!_LIBCUDACXX_TRAIT(is_same, _Up, nullopt_t), + "Result of f(std::move(value())) should not be std::nullopt_t"); + static_assert(_LIBCUDACXX_TRAIT(is_object, _Up), "Result of f(std::move(value())) should be an object type"); + if (this->__engaged_) + { + return optional<_Up>( + __optional_construct_from_invoke_tag{}, _CUDA_VSTD::forward<_Func>(__f), _CUDA_VSTD::move(this->__get())); } + return optional<_Up>(); + } - _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) - _LIBCUDACXX_REQUIRES( invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp2)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional or_else(_Func&& __f) const& { - static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), - "Result of f() should be the same type as this optional"); - if (this->__engaged_) - { - return *this; - } - return _CUDA_VSTD::forward<_Func>(__f)(); + _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) + _LIBCUDACXX_REQUIRES(invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_copy_constructible, _Tp2)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional or_else(_Func&& __f) const& + { + static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), + "Result of f() should be the same type as this optional"); + if (this->__engaged_) + { + return *this; } + return _CUDA_VSTD::forward<_Func>(__f)(); + } - _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) - _LIBCUDACXX_REQUIRES( invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_move_constructible, _Tp2)) - _LIBCUDACXX_INLINE_VISIBILITY constexpr - optional or_else(_Func&& __f) && { - static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), - "Result of f() should be the same type as this optional"); - if (this->__engaged_) - { - return _CUDA_VSTD::move(*this); - } - return _CUDA_VSTD::forward<_Func>(__f)(); + _LIBCUDACXX_TEMPLATE(class _Func, class _Tp2 = _Tp) + _LIBCUDACXX_REQUIRES(invocable<_Func> _LIBCUDACXX_AND _LIBCUDACXX_TRAIT(is_move_constructible, _Tp2)) + _LIBCUDACXX_INLINE_VISIBILITY constexpr optional or_else(_Func&& __f) && + { + static_assert(_LIBCUDACXX_TRAIT(is_same, remove_cvref_t>, optional), + "Result of f() should be the same type as this optional"); + if (this->__engaged_) + { + return _CUDA_VSTD::move(*this); } + return _CUDA_VSTD::forward<_Func>(__f)(); + } - using __base::reset; + using __base::reset; }; -#if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) -template +# if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) +template _CCCL_HOST_DEVICE optional(_Tp) -> optional<_Tp>; -#endif +# endif // Comparisons between optionals template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), + bool> operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (static_cast(__x) != static_cast(__y)) - return false; - if (!static_cast(__x)) - return true; - return *__x == *__y; + if (static_cast(__x) != static_cast(__y)) + { + return false; + } + if (!static_cast(__x)) + { + return true; + } + return *__x == *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != declval()), bool), + bool> operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (static_cast(__x) != static_cast(__y)) - return true; - if (!static_cast(__x)) - return false; - return *__x != *__y; + if (static_cast(__x) != static_cast(__y)) + { + return true; + } + if (!static_cast(__x)) + { + return false; + } + return *__x != *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < declval()), bool), + bool> operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__y)) - return false; - if (!static_cast(__x)) - return true; - return *__x < *__y; + if (!static_cast(__y)) + { + return false; + } + if (!static_cast(__x)) + { + return true; + } + return *__x < *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > declval()), bool), + bool> operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__x)) - return false; - if (!static_cast(__y)) - return true; - return *__x > *__y; + if (!static_cast(__x)) + { + return false; + } + if (!static_cast(__y)) + { + return true; + } + return *__x > *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= declval()), bool), + bool> operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__x)) - return true; - if (!static_cast(__y)) - return false; - return *__x <= *__y; + if (!static_cast(__x)) + { + return true; + } + if (!static_cast(__y)) + { + return false; + } + return *__x <= *__y; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= declval()), bool), + bool> operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) { - if (!static_cast(__y)) - return true; - if (!static_cast(__x)) - return false; - return *__x >= *__y; + if (!static_cast(__y)) + { + return true; + } + if (!static_cast(__x)) + { + return false; + } + return *__x >= *__y; } // Comparisons with nullopt template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator==(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator==(const optional<_Tp>& __x, nullopt_t) noexcept { - return !static_cast(__x); + return !static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator==(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator==(nullopt_t, const optional<_Tp>& __x) noexcept { - return !static_cast(__x); + return !static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator!=(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator!=(const optional<_Tp>& __x, nullopt_t) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator!=(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator!=(nullopt_t, const optional<_Tp>& __x) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<(const optional<_Tp>&, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<(const optional<_Tp>&, nullopt_t) noexcept { - return false; + return false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<(nullopt_t, const optional<_Tp>& __x) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<=(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<=(const optional<_Tp>& __x, nullopt_t) noexcept { - return !static_cast(__x); + return !static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator<=(nullopt_t, const optional<_Tp>&) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<=(nullopt_t, const optional<_Tp>&) noexcept { - return true; + return true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>(const optional<_Tp>& __x, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>(const optional<_Tp>& __x, nullopt_t) noexcept { - return static_cast(__x); + return static_cast(__x); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>(nullopt_t, const optional<_Tp>&) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>(nullopt_t, const optional<_Tp>&) noexcept { - return false; + return false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>=(const optional<_Tp>&, nullopt_t) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>=(const optional<_Tp>&, nullopt_t) noexcept { - return true; + return true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -bool -operator>=(nullopt_t, const optional<_Tp>& __x) noexcept +_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>=(nullopt_t, const optional<_Tp>& __x) noexcept { - return !static_cast(__x); + return !static_cast(__x); } // Comparisons with T template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), + bool> operator==(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x == __v : false; + return static_cast(__x) ? *__x == __v : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() == declval()), bool), + bool> operator==(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v == *__x : false; + return static_cast(__x) ? __v == *__x : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != declval()), bool), + bool> operator!=(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x != __v : true; + return static_cast(__x) ? *__x != __v : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() != declval()), bool), + bool> operator!=(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v != *__x : true; + return static_cast(__x) ? __v != *__x : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < declval()), bool), + bool> operator<(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x < __v : true; + return static_cast(__x) ? *__x < __v : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() < declval()), bool), + bool> operator<(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v < *__x : false; + return static_cast(__x) ? __v < *__x : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= declval()), bool), + bool> operator<=(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x <= __v : true; + return static_cast(__x) ? *__x <= __v : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() <= declval()), bool), + bool> operator<=(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v <= *__x : false; + return static_cast(__x) ? __v <= *__x : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > declval()), bool), + bool> operator>(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x > __v : false; + return static_cast(__x) ? *__x > __v : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() > declval()), bool), + bool> operator>(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v > *__x : true; + return static_cast(__x) ? __v > *__x : true; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= declval()), bool), + bool> operator>=(const optional<_Tp>& __x, const _Up& __v) { - return static_cast(__x) ? *__x >= __v : false; + return static_cast(__x) ? *__x >= __v : false; } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= - declval()), bool), - bool -> +_LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_convertible, decltype(declval() >= declval()), bool), + bool> operator>=(const _Tp& __v, const optional<_Up>& __x) { - return static_cast(__x) ? __v >= *__x : true; + return static_cast(__x) ? __v >= *__x : true; } - template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr -__enable_if_t< - _LIBCUDACXX_TRAIT(is_move_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_swappable, _Tp), - void -> +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr __enable_if_t< + _LIBCUDACXX_TRAIT(is_move_constructible, _Tp) && _LIBCUDACXX_TRAIT(is_swappable, _Tp), + void> swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) { - __x.swap(__y); + __x.swap(__y); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -optional> make_optional(_Tp&& __v) +_LIBCUDACXX_INLINE_VISIBILITY constexpr optional> make_optional(_Tp&& __v) { - return optional>(_CUDA_VSTD::forward<_Tp>(__v)); + return optional>(_CUDA_VSTD::forward<_Tp>(__v)); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -optional<_Tp> make_optional(_Args&&... __args) +_LIBCUDACXX_INLINE_VISIBILITY constexpr optional<_Tp> make_optional(_Args&&... __args) { - return optional<_Tp>(in_place, _CUDA_VSTD::forward<_Args>(__args)...); + return optional<_Tp>(in_place, _CUDA_VSTD::forward<_Args>(__args)...); } template -_LIBCUDACXX_INLINE_VISIBILITY constexpr -optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args) +_LIBCUDACXX_INLINE_VISIBILITY constexpr optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args) { - return optional<_Tp>(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...); + return optional<_Tp>(in_place, __il, _CUDA_VSTD::forward<_Args>(__args)...); } -#ifndef __cuda_std__ +# ifndef __cuda_std__ template -struct _LIBCUDACXX_TEMPLATE_VIS hash< - __enable_hash_helper, remove_const_t<_Tp>> -> +struct _LIBCUDACXX_TEMPLATE_VIS hash<__enable_hash_helper, remove_const_t<_Tp>>> { -#if _CCCL_STD_VER <= 2017 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) - _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type; - _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef size_t result_type; -#endif +# if _CCCL_STD_VER <= 2017 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type; + _LIBCUDACXX_DEPRECATED_IN_CXX17 typedef size_t result_type; +# endif - _LIBCUDACXX_INLINE_VISIBILITY - size_t operator()(const optional<_Tp>& __opt) const - { - return static_cast(__opt) ? hash>()(*__opt) : 0; - } + _LIBCUDACXX_INLINE_VISIBILITY size_t operator()(const optional<_Tp>& __opt) const + { + return static_cast(__opt) ? hash>()(*__opt) : 0; + } }; -#endif // __cuda_std__ +# endif // __cuda_std__ _LIBCUDACXX_END_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/ranges b/libcudacxx/include/cuda/std/detail/libcxx/include/ranges index a7c26c7f63c..30174b96dca 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/ranges +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/ranges @@ -320,7 +320,6 @@ namespace std { _CCCL_DIAG_PUSH _CCCL_DIAG_SUPPRESS_MSVC(4848) -#include // all public C++ headers provide the assertion handler #include #include #include @@ -334,13 +333,14 @@ _CCCL_DIAG_SUPPRESS_MSVC(4848) #include #include #include +#include // all public C++ headers provide the assertion handler // standard-mandated includes #include // [ranges.syn] #ifndef _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR -#include +# include #endif // _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR #include #include diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/ratio b/libcudacxx/include/cuda/std/detail/libcxx/include/ratio index edf8d224c91..6e47145ddca 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/ratio +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/ratio @@ -87,10 +87,10 @@ typedef ratio<1000000000000000000000000, 1> yotta; // not supported # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include +#include // all public C++ headers provide the assertion handler #include #include @@ -102,19 +102,19 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD template struct __static_gcd { - static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value; + static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value; }; template struct __static_gcd<_Xp, 0> { - static const intmax_t value = _Xp; + static const intmax_t value = _Xp; }; template <> struct __static_gcd<0, 0> { - static const intmax_t value = 1; + static const intmax_t value = 1; }; // __static_lcm @@ -122,19 +122,19 @@ struct __static_gcd<0, 0> template struct __static_lcm { - static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp; + static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp; }; template struct __static_abs { - static const intmax_t value = _Xp < 0 ? -_Xp : _Xp; + static const intmax_t value = _Xp < 0 ? -_Xp : _Xp; }; template struct __static_sign { - static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1); + static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1); }; template ::value> @@ -143,30 +143,32 @@ class __ll_add; template class __ll_add<_Xp, _Yp, 1> { - static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; - static const intmax_t max = -min; + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(_Xp <= max - _Yp, "overflow in __ll_add"); - static_assert(_Xp <= max - _Yp, "overflow in __ll_add"); public: - static const intmax_t value = _Xp + _Yp; + static const intmax_t value = _Xp + _Yp; }; template class __ll_add<_Xp, _Yp, 0> { public: - static const intmax_t value = _Xp; + static const intmax_t value = _Xp; }; template class __ll_add<_Xp, _Yp, -1> { - static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; - static const intmax_t max = -min; + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(min - _Yp <= _Xp, "overflow in __ll_add"); - static_assert(min - _Yp <= _Xp, "overflow in __ll_add"); public: - static const intmax_t value = _Xp + _Yp; + static const intmax_t value = _Xp + _Yp; }; template ::value> @@ -175,95 +177,100 @@ class __ll_sub; template class __ll_sub<_Xp, _Yp, 1> { - static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; - static const intmax_t max = -min; + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(min + _Yp <= _Xp, "overflow in __ll_sub"); - static_assert(min + _Yp <= _Xp, "overflow in __ll_sub"); public: - static const intmax_t value = _Xp - _Yp; + static const intmax_t value = _Xp - _Yp; }; template class __ll_sub<_Xp, _Yp, 0> { public: - static const intmax_t value = _Xp; + static const intmax_t value = _Xp; }; template class __ll_sub<_Xp, _Yp, -1> { - static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; - static const intmax_t max = -min; + static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1; + static const intmax_t max = -min; + + static_assert(_Xp <= max + _Yp, "overflow in __ll_sub"); - static_assert(_Xp <= max + _Yp, "overflow in __ll_sub"); public: - static const intmax_t value = _Xp - _Yp; + static const intmax_t value = _Xp - _Yp; }; template class __ll_mul { - static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); - static const intmax_t min = nan + 1; - static const intmax_t max = -min; - static const intmax_t __a_x = __static_abs<_Xp>::value; - static const intmax_t __a_y = __static_abs<_Yp>::value; + static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); + static const intmax_t min = nan + 1; + static const intmax_t max = -min; + static const intmax_t __a_x = __static_abs<_Xp>::value; + static const intmax_t __a_y = __static_abs<_Yp>::value; + + static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul"); - static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul"); public: - static const intmax_t value = _Xp * _Yp; + static const intmax_t value = _Xp * _Yp; }; template class __ll_mul<0, _Yp> { public: - static const intmax_t value = 0; + static const intmax_t value = 0; }; template class __ll_mul<_Xp, 0> { public: - static const intmax_t value = 0; + static const intmax_t value = 0; }; template <> class __ll_mul<0, 0> { public: - static const intmax_t value = 0; + static const intmax_t value = 0; }; // Not actually used but left here in case needed in future maintenance template class __ll_div { - static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); - static const intmax_t min = nan + 1; - static const intmax_t max = -min; + static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)); + static const intmax_t min = nan + 1; + static const intmax_t max = -min; + + static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div"); - static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div"); public: - static const intmax_t value = _Xp / _Yp; + static const intmax_t value = _Xp / _Yp; }; template class _LIBCUDACXX_TEMPLATE_VIS ratio { - static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range"); - static_assert(_Den != 0, "ratio divide by 0"); - static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range"); - static constexpr intmax_t __na = __static_abs<_Num>::value; - static constexpr intmax_t __da = __static_abs<_Den>::value; - static constexpr intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value; - static constexpr intmax_t __gcd = __static_gcd<__na, __da>::value; + static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range"); + static_assert(_Den != 0, "ratio divide by 0"); + static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range"); + static constexpr intmax_t __na = __static_abs<_Num>::value; + static constexpr intmax_t __da = __static_abs<_Den>::value; + static constexpr intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value; + static constexpr intmax_t __gcd = __static_gcd<__na, __da>::value; + public: - static constexpr intmax_t num = __s * __na / __gcd; - static constexpr intmax_t den = __da / __gcd; + static constexpr intmax_t num = __s * __na / __gcd; + static constexpr intmax_t den = __da / __gcd; - typedef ratio type; + typedef ratio type; }; template @@ -272,226 +279,210 @@ constexpr intmax_t ratio<_Num, _Den>::num; template constexpr intmax_t ratio<_Num, _Den>::den; -template struct __is_ratio : false_type {}; -template struct __is_ratio > : true_type {}; +template +struct __is_ratio : false_type +{}; +template +struct __is_ratio> : true_type +{}; typedef ratio<1LL, 1000000000000000000LL> atto; -typedef ratio<1LL, 1000000000000000LL> femto; -typedef ratio<1LL, 1000000000000LL> pico; -typedef ratio<1LL, 1000000000LL> nano; -typedef ratio<1LL, 1000000LL> micro; -typedef ratio<1LL, 1000LL> milli; -typedef ratio<1LL, 100LL> centi; -typedef ratio<1LL, 10LL> deci; -typedef ratio< 10LL, 1LL> deca; -typedef ratio< 100LL, 1LL> hecto; -typedef ratio< 1000LL, 1LL> kilo; -typedef ratio< 1000000LL, 1LL> mega; -typedef ratio< 1000000000LL, 1LL> giga; -typedef ratio< 1000000000000LL, 1LL> tera; -typedef ratio< 1000000000000000LL, 1LL> peta; +typedef ratio<1LL, 1000000000000000LL> femto; +typedef ratio<1LL, 1000000000000LL> pico; +typedef ratio<1LL, 1000000000LL> nano; +typedef ratio<1LL, 1000000LL> micro; +typedef ratio<1LL, 1000LL> milli; +typedef ratio<1LL, 100LL> centi; +typedef ratio<1LL, 10LL> deci; +typedef ratio<10LL, 1LL> deca; +typedef ratio<100LL, 1LL> hecto; +typedef ratio<1000LL, 1LL> kilo; +typedef ratio<1000000LL, 1LL> mega; +typedef ratio<1000000000LL, 1LL> giga; +typedef ratio<1000000000000LL, 1LL> tera; +typedef ratio<1000000000000000LL, 1LL> peta; typedef ratio<1000000000000000000LL, 1LL> exa; template struct __ratio_multiply { -//private: - static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value; - static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value; + // private: + static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value; + static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value; + public: - typedef typename ratio - < - __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value, - __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value - >::type type; + typedef typename ratio<__ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value, + __ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value>::type type; }; -template using ratio_multiply - = typename __ratio_multiply<_R1, _R2>::type; +template +using ratio_multiply = typename __ratio_multiply<_R1, _R2>::type; template struct __ratio_divide { -//private: - static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; - static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + // private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + public: - typedef typename ratio - < - __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, - __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value - >::type type; + typedef typename ratio<__ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, + __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value>::type type; }; -template using ratio_divide - = typename __ratio_divide<_R1, _R2>::type; +template +using ratio_divide = typename __ratio_divide<_R1, _R2>::type; template struct __ratio_add { -//private: - static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; - static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + // private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + public: - typedef typename ratio_multiply - < - ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, - ratio - < - __ll_add - < - __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, - __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value - >::value, - _R2::den - > - >::type type; -}; - -template using ratio_add - = typename __ratio_add<_R1, _R2>::type; + typedef + typename ratio_multiply, + ratio<__ll_add<__ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, + __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value>::value, + _R2::den>>::type type; +}; + +template +using ratio_add = typename __ratio_add<_R1, _R2>::type; template struct __ratio_subtract { -//private: - static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; - static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + // private: + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + public: - typedef typename ratio_multiply - < - ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>, - ratio - < - __ll_sub - < - __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, - __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value - >::value, - _R2::den - > - >::type type; -}; - -template using ratio_subtract - = typename __ratio_subtract<_R1, _R2>::type; + typedef + typename ratio_multiply, + ratio<__ll_sub<__ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value, + __ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value>::value, + _R2::den>>::type type; +}; + +template +using ratio_subtract = typename __ratio_subtract<_R1, _R2>::type; // ratio_equal template struct _LIBCUDACXX_TEMPLATE_VIS ratio_equal - : public _LIBCUDACXX_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den)) {}; + : public _LIBCUDACXX_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den)) +{}; template -struct _LIBCUDACXX_TEMPLATE_VIS ratio_not_equal - : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value)) {}; +struct _LIBCUDACXX_TEMPLATE_VIS ratio_not_equal : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value)) +{}; // ratio_less -template +template struct __ratio_less1 { - static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2; + static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2; }; template struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, 0> { - static const bool value = false; + static const bool value = false; }; template struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, _M2> { - static const bool value = !_Odd; + static const bool value = !_Odd; }; template struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, 0> { - static const bool value = _Odd; + static const bool value = _Odd; }; -template +template struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2> { - static const bool value = __ratio_less1, - ratio<_R2::den, _M2>, !_Odd>::value; + static const bool value = __ratio_less1, ratio<_R2::den, _M2>, !_Odd>::value; }; -template ::value, - intmax_t _S2 = __static_sign<_R2::num>::value> +template ::value, + intmax_t _S2 = __static_sign<_R2::num>::value> struct __ratio_less { - static const bool value = _S1 < _S2; + static const bool value = _S1 < _S2; }; template struct __ratio_less<_R1, _R2, 1LL, 1LL> { - static const bool value = __ratio_less1<_R1, _R2>::value; + static const bool value = __ratio_less1<_R1, _R2>::value; }; template struct __ratio_less<_R1, _R2, -1LL, -1LL> { - static const bool value = __ratio_less1, ratio<-_R1::num, _R1::den> >::value; + static const bool value = __ratio_less1, ratio<-_R1::num, _R1::den>>::value; }; template -struct _LIBCUDACXX_TEMPLATE_VIS ratio_less - : public _LIBCUDACXX_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value)) {}; +struct _LIBCUDACXX_TEMPLATE_VIS ratio_less : public _LIBCUDACXX_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value)) +{}; template -struct _LIBCUDACXX_TEMPLATE_VIS ratio_less_equal - : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value)) {}; +struct _LIBCUDACXX_TEMPLATE_VIS ratio_less_equal : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value)) +{}; template -struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater - : public _LIBCUDACXX_BOOL_CONSTANT((ratio_less<_R2, _R1>::value)) {}; +struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater : public _LIBCUDACXX_BOOL_CONSTANT((ratio_less<_R2, _R1>::value)) +{}; template -struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater_equal - : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value)) {}; +struct _LIBCUDACXX_TEMPLATE_VIS ratio_greater_equal : public _LIBCUDACXX_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value)) +{}; template struct __ratio_gcd { - typedef ratio<__static_gcd<_R1::num, _R2::num>::value, - __static_lcm<_R1::den, _R2::den>::value> type; + typedef ratio<__static_gcd<_R1::num, _R2::num>::value, __static_lcm<_R1::den, _R2::den>::value> type; }; #if _CCCL_STD_VER > 2014 && !defined(_LIBCUDACXX_HAS_NO_VARIABLE_TEMPLATES) template -_LIBCUDACXX_INLINE_VAR constexpr bool ratio_equal_v - = ratio_equal<_R1, _R2>::value; +_LIBCUDACXX_INLINE_VAR constexpr bool ratio_equal_v = ratio_equal<_R1, _R2>::value; template -_LIBCUDACXX_INLINE_VAR constexpr bool ratio_not_equal_v - = ratio_not_equal<_R1, _R2>::value; +_LIBCUDACXX_INLINE_VAR constexpr bool ratio_not_equal_v = ratio_not_equal<_R1, _R2>::value; template -_LIBCUDACXX_INLINE_VAR constexpr bool ratio_less_v - = ratio_less<_R1, _R2>::value; +_LIBCUDACXX_INLINE_VAR constexpr bool ratio_less_v = ratio_less<_R1, _R2>::value; template -_LIBCUDACXX_INLINE_VAR constexpr bool ratio_less_equal_v - = ratio_less_equal<_R1, _R2>::value; +_LIBCUDACXX_INLINE_VAR constexpr bool ratio_less_equal_v = ratio_less_equal<_R1, _R2>::value; template -_LIBCUDACXX_INLINE_VAR constexpr bool ratio_greater_v - = ratio_greater<_R1, _R2>::value; +_LIBCUDACXX_INLINE_VAR constexpr bool ratio_greater_v = ratio_greater<_R1, _R2>::value; template -_LIBCUDACXX_INLINE_VAR constexpr bool ratio_greater_equal_v - = ratio_greater_equal<_R1, _R2>::value; +_LIBCUDACXX_INLINE_VAR constexpr bool ratio_greater_equal_v = ratio_greater_equal<_R1, _R2>::value; #endif _LIBCUDACXX_END_NAMESPACE_STD #include //__cuda_std__ -#endif // _LIBCUDACXX_RATIO +#endif // _LIBCUDACXX_RATIO diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/semaphore b/libcudacxx/include/cuda/std/detail/libcxx/include/semaphore index f038532e775..a0909dccbfe 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/semaphore +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/semaphore @@ -55,387 +55,429 @@ using binary_semaphore = counting_semaphore<1>; # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include +#include // all public C++ headers provide the assertion handler #include #include #ifdef _LIBCUDACXX_HAS_NO_THREADS -# error is not supported on this single threaded system +# error is not supported on this single threaded system #endif _LIBCUDACXX_BEGIN_NAMESPACE_STD -template +template class __atomic_semaphore_base { - _LIBCUDACXX_INLINE_VISIBILITY - bool __fetch_sub_if_slow(ptrdiff_t __old) + _LIBCUDACXX_INLINE_VISIBILITY bool __fetch_sub_if_slow(ptrdiff_t __old) + { + while (__old != 0) { - while (__old != 0) { - if (__count.compare_exchange_weak(__old, __old - 1, memory_order_acquire, memory_order_relaxed)) - return true; - } - return false; + if (__count.compare_exchange_weak(__old, __old - 1, memory_order_acquire, memory_order_relaxed)) + { + return true; + } } + return false; + } - _LIBCUDACXX_INLINE_VISIBILITY - bool __fetch_sub_if() + _LIBCUDACXX_INLINE_VISIBILITY bool __fetch_sub_if() + { + ptrdiff_t __old = __count.load(memory_order_acquire); + if (__old == 0) { - ptrdiff_t __old = __count.load(memory_order_acquire); - if (__old == 0) - return false; - if(__count.compare_exchange_weak(__old, __old - 1, memory_order_acquire, memory_order_relaxed)) - return true; - return __fetch_sub_if_slow(__old); // fail only if not __available + return false; } - - _LIBCUDACXX_INLINE_VISIBILITY - void __wait_slow() + if (__count.compare_exchange_weak(__old, __old - 1, memory_order_acquire, memory_order_relaxed)) { - while (1) { - ptrdiff_t const __old = __count.load(memory_order_acquire); - if(__old != 0) - break; - __count.wait(__old, memory_order_relaxed); - } + return true; } + return __fetch_sub_if_slow(__old); // fail only if not __available + } - _LIBCUDACXX_INLINE_VISIBILITY - bool __acquire_slow_timed(chrono::nanoseconds const& __rel_time) + _LIBCUDACXX_INLINE_VISIBILITY void __wait_slow() + { + while (1) { - return __libcpp_thread_poll_with_backoff([this]() { - ptrdiff_t const __old = __count.load(memory_order_acquire); - return __old != 0 && __fetch_sub_if_slow(__old); - }, __rel_time); + ptrdiff_t const __old = __count.load(memory_order_acquire); + if (__old != 0) + { + break; + } + __count.wait(__old, memory_order_relaxed); } - __atomic_base __count; + } + + _LIBCUDACXX_INLINE_VISIBILITY bool __acquire_slow_timed(chrono::nanoseconds const& __rel_time) + { + return __libcpp_thread_poll_with_backoff( + [this]() { + ptrdiff_t const __old = __count.load(memory_order_acquire); + return __old != 0 && __fetch_sub_if_slow(__old); + }, + __rel_time); + } + __atomic_base __count; public: - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr ptrdiff_t max() noexcept - { - return numeric_limits::max(); - } + _LIBCUDACXX_INLINE_VISIBILITY static constexpr ptrdiff_t max() noexcept + { + return numeric_limits::max(); + } - _LIBCUDACXX_INLINE_VISIBILITY constexpr - __atomic_semaphore_base(ptrdiff_t __count) noexcept : __count(__count) { } + _LIBCUDACXX_INLINE_VISIBILITY constexpr __atomic_semaphore_base(ptrdiff_t __count) noexcept + : __count(__count) + {} - ~__atomic_semaphore_base() = default; + ~__atomic_semaphore_base() = default; - __atomic_semaphore_base(__atomic_semaphore_base const&) = delete; - __atomic_semaphore_base& operator=(__atomic_semaphore_base const&) = delete; + __atomic_semaphore_base(__atomic_semaphore_base const&) = delete; + __atomic_semaphore_base& operator=(__atomic_semaphore_base const&) = delete; - _LIBCUDACXX_INLINE_VISIBILITY - void release(ptrdiff_t __update = 1) + _LIBCUDACXX_INLINE_VISIBILITY void release(ptrdiff_t __update = 1) + { + __count.fetch_add(__update, memory_order_release); + if (__update > 1) { - __count.fetch_add(__update, memory_order_release); - if(__update > 1) - __count.notify_all(); - else - __count.notify_one(); + __count.notify_all(); } - - _LIBCUDACXX_INLINE_VISIBILITY - void acquire() + else { - while (!try_acquire()) - __wait_slow(); + __count.notify_one(); } + } - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire() noexcept + _LIBCUDACXX_INLINE_VISIBILITY void acquire() + { + while (!try_acquire()) { - return __fetch_sub_if(); + __wait_slow(); } + } + + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire() noexcept + { + return __fetch_sub_if(); + } - template - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire_until(chrono::time_point const& __abs_time) + template + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire_until(chrono::time_point const& __abs_time) + { + if (try_acquire()) { - if (try_acquire()) - return true; - else - return __acquire_slow_timed(__abs_time - Clock::now()); + return true; } - - template - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire_for(chrono::duration const& __rel_time) + else { + return __acquire_slow_timed(__abs_time - Clock::now()); + } + } - if (try_acquire()) - return true; - else - return __acquire_slow_timed(__rel_time); + template + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire_for(chrono::duration const& __rel_time) + { + if (try_acquire()) + { + return true; } + else + { + return __acquire_slow_timed(__rel_time); + } + } }; #ifndef _LIBCUDACXX_USE_NATIVE_SEMAPHORES -template -class __atomic_semaphore_base<_Sco, 1> { - - _LIBCUDACXX_INLINE_VISIBILITY - bool __acquire_slow_timed(chrono::nanoseconds const& __rel_time) - { - return __libcpp_thread_poll_with_backoff([this]() { - return try_acquire(); - }, __rel_time); - } - __atomic_base __available; +template +class __atomic_semaphore_base<_Sco, 1> +{ + _LIBCUDACXX_INLINE_VISIBILITY bool __acquire_slow_timed(chrono::nanoseconds const& __rel_time) + { + return __libcpp_thread_poll_with_backoff( + [this]() { + return try_acquire(); + }, + __rel_time); + } + __atomic_base __available; public: - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr ptrdiff_t max() noexcept { return 1; } - - _LIBCUDACXX_INLINE_VISIBILITY constexpr - __atomic_semaphore_base(ptrdiff_t __available) : __available(__available) { } - - ~__atomic_semaphore_base() = default; - - __atomic_semaphore_base(__atomic_semaphore_base const&) = delete; - __atomic_semaphore_base& operator=(__atomic_semaphore_base const&) = delete; - - _LIBCUDACXX_INLINE_VISIBILITY - void release(ptrdiff_t __update = 1) + _LIBCUDACXX_INLINE_VISIBILITY static constexpr ptrdiff_t max() noexcept + { + return 1; + } + + _LIBCUDACXX_INLINE_VISIBILITY constexpr __atomic_semaphore_base(ptrdiff_t __available) + : __available(__available) + {} + + ~__atomic_semaphore_base() = default; + + __atomic_semaphore_base(__atomic_semaphore_base const&) = delete; + __atomic_semaphore_base& operator=(__atomic_semaphore_base const&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY void release(ptrdiff_t __update = 1) + { + _LIBCUDACXX_ASSERT(__update == 1, ""); + __available.store(1, memory_order_release); + __available.notify_one(); + (void) __update; + } + + _LIBCUDACXX_INLINE_VISIBILITY void acquire() + { + while (!try_acquire()) { - _LIBCUDACXX_ASSERT(__update == 1, ""); - __available.store(1, memory_order_release); - __available.notify_one(); - (void)__update; + __available.wait(0, memory_order_relaxed); } + } + + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire() noexcept + { + return 1 == __available.exchange(0, memory_order_acquire); + } - _LIBCUDACXX_INLINE_VISIBILITY - void acquire() + template + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire_until(chrono::time_point const& __abs_time) + { + if (try_acquire()) { - while (!try_acquire()) - __available.wait(0, memory_order_relaxed); + return true; } - - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire() noexcept + else { - return 1 == __available.exchange(0, memory_order_acquire); + return __acquire_slow_timed(__abs_time - Clock::now()); } + } - template - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire_until(chrono::time_point const& __abs_time) + template + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire_for(chrono::duration const& __rel_time) + { + if (try_acquire()) { - if (try_acquire()) - return true; - else - return __acquire_slow_timed(__abs_time - Clock::now()); + return true; } - - template - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire_for(chrono::duration const& __rel_time) + else { - if (try_acquire()) - return true; - else - return __acquire_slow_timed(__rel_time); + return __acquire_slow_timed(__rel_time); } + } }; #else -template -class __sem_semaphore_base { - - _LIBCUDACXX_INLINE_VISIBILITY - bool __backfill(bool __success) - { -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER - if(__success) { - auto const __back_amount = __backbuffer.fetch_sub(2, memory_order_acquire); - bool const __post_one = __back_amount > 0; - bool const __post_two = __back_amount > 1; - auto const __success = (!__post_one || __libcpp_semaphore_post(&__semaphore)) && - (!__post_two || __libcpp_semaphore_post(&__semaphore)); - _LIBCUDACXX_ASSERT(__success, ""); - if(!__post_one || !__post_two) - __backbuffer.fetch_add(!__post_one ? 2 : 1, memory_order_relaxed); - } -#endif - return __success; - } - - _LIBCUDACXX_INLINE_VISIBILITY - bool __try_acquire_fast() +template +class __sem_semaphore_base +{ + _LIBCUDACXX_INLINE_VISIBILITY bool __backfill(bool __success) + { +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER + if (__success) { -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER - - ptrdiff_t __old; - __libcpp_thread_poll_with_backoff([&]() { - __old = __frontbuffer.load(memory_order_relaxed); - return 0 != (__old >> 32); - }, chrono::microseconds(5)); - - // always steal if you can - while(__old >> 32) - if(__frontbuffer.compare_exchange_weak(__old, __old - (1ll << 32), memory_order_acquire)) - return true; - // record we're waiting - __old = __frontbuffer.fetch_add(1ll, memory_order_release); - // ALWAYS steal if you can! - while(__old >> 32) - if(__frontbuffer.compare_exchange_weak(__old, __old - (1ll << 32), memory_order_acquire)) - break; - // not going to wait after all - if(__old >> 32) - return __try_done(true); -#endif - // the wait has begun... - return false; + auto const __back_amount = __backbuffer.fetch_sub(2, memory_order_acquire); + bool const __post_one = __back_amount > 0; + bool const __post_two = __back_amount > 1; + auto const __success = (!__post_one || __libcpp_semaphore_post(&__semaphore)) + && (!__post_two || __libcpp_semaphore_post(&__semaphore)); + _LIBCUDACXX_ASSERT(__success, ""); + if (!__post_one || !__post_two) + { + __backbuffer.fetch_add(!__post_one ? 2 : 1, memory_order_relaxed); + } } - - _LIBCUDACXX_INLINE_VISIBILITY - bool __try_done(bool __success) +# endif + return __success; + } + + _LIBCUDACXX_INLINE_VISIBILITY bool __try_acquire_fast() + { +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER + + ptrdiff_t __old; + __libcpp_thread_poll_with_backoff( + [&]() { + __old = __frontbuffer.load(memory_order_relaxed); + return 0 != (__old >> 32); + }, + chrono::microseconds(5)); + + // always steal if you can + while (__old >> 32) { -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER - // record we're NOT waiting - __frontbuffer.fetch_sub(1ll, memory_order_release); -#endif - return __backfill(__success); + if (__frontbuffer.compare_exchange_weak(__old, __old - (1ll << 32), memory_order_acquire)) + { + return true; + } } - - _LIBCUDACXX_INLINE_VISIBILITY - void __release_slow(ptrdiff_t __post_amount) + // record we're waiting + __old = __frontbuffer.fetch_add(1ll, memory_order_release); + // ALWAYS steal if you can! + while (__old >> 32) { - #ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER - bool const __post_one = __post_amount > 0; - bool const __post_two = __post_amount > 1; - if(__post_amount > 2) - __backbuffer.fetch_add(__post_amount - 2, memory_order_acq_rel); - auto const __success = (!__post_one || __libcpp_semaphore_post(&__semaphore)) && - (!__post_two || __libcpp_semaphore_post(&__semaphore)); - _LIBCUDACXX_ASSERT(__success, ""); - #else - for(; __post_amount; --__post_amount) { - auto const __success = __libcpp_semaphore_post(&__semaphore); - _LIBCUDACXX_ASSERT(__success, ""); - } - #endif - } - - __libcpp_semaphore_t __semaphore; -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER - __atomic_base __frontbuffer; -#endif -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER - __atomic_base __backbuffer; -#endif - -public: - static constexpr ptrdiff_t max() noexcept { - return _LIBCUDACXX_SEMAPHORE_MAX; + if (__frontbuffer.compare_exchange_weak(__old, __old - (1ll << 32), memory_order_acquire)) + { + break; + } } - - _LIBCUDACXX_INLINE_VISIBILITY - __sem_semaphore_base(ptrdiff_t __count = 0) : __semaphore() -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER - , __frontbuffer(__count << 32) -#endif -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER - , __backbuffer(0) -#endif + // not going to wait after all + if (__old >> 32) { - _LIBCUDACXX_ASSERT(__count <= max(), ""); - auto const __success = -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER - __libcpp_semaphore_init(&__semaphore, 0); -#else - __libcpp_semaphore_init(&__semaphore, __count); -#endif - _LIBCUDACXX_ASSERT(__success, ""); + return __try_done(true); } - - _LIBCUDACXX_INLINE_VISIBILITY - ~__sem_semaphore_base() { -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER - _LIBCUDACXX_ASSERT(0 == (__frontbuffer.load(memory_order_relaxed) & ~0u), ""); -#endif - auto const __success = __libcpp_semaphore_destroy(&__semaphore); - _LIBCUDACXX_ASSERT(__success, ""); - } - - __sem_semaphore_base(const __sem_semaphore_base&) = delete; - __sem_semaphore_base& operator=(const __sem_semaphore_base&) = delete; - - _LIBCUDACXX_INLINE_VISIBILITY - void release(ptrdiff_t __update = 1) +# endif + // the wait has begun... + return false; + } + + _LIBCUDACXX_INLINE_VISIBILITY bool __try_done(bool __success) + { +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER + // record we're NOT waiting + __frontbuffer.fetch_sub(1ll, memory_order_release); +# endif + return __backfill(__success); + } + + _LIBCUDACXX_INLINE_VISIBILITY void __release_slow(ptrdiff_t __post_amount) + { +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER + bool const __post_one = __post_amount > 0; + bool const __post_two = __post_amount > 1; + if (__post_amount > 2) { -#ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER - // boldly assume the semaphore is taken but uncontended - ptrdiff_t __old = 0; - // try to fast-release as long as it's uncontended - while(0 == (__old & ~0ul)) - if(__frontbuffer.compare_exchange_weak(__old, __old + (__update << 32), memory_order_acq_rel)) - return; -#endif - // slow-release it is - __release_slow(__update); + __backbuffer.fetch_add(__post_amount - 2, memory_order_acq_rel); } - - _LIBCUDACXX_INLINE_VISIBILITY - void acquire() + auto const __success = + (!__post_one || __libcpp_semaphore_post(&__semaphore)) && (!__post_two || __libcpp_semaphore_post(&__semaphore)); + _LIBCUDACXX_ASSERT(__success, ""); +# else + for (; __post_amount; --__post_amount) { - if(!__try_acquire_fast()) - __try_done(__libcpp_semaphore_wait(&__semaphore)); + auto const __success = __libcpp_semaphore_post(&__semaphore); + _LIBCUDACXX_ASSERT(__success, ""); } +# endif + } - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire() noexcept - { - return try_acquire_for(chrono::nanoseconds(0)); - } + __libcpp_semaphore_t __semaphore; +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER + __atomic_base __frontbuffer; +# endif +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER + __atomic_base __backbuffer; +# endif - template - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire_until(chrono::time_point const& __abs_time) +public: + static constexpr ptrdiff_t max() noexcept + { + return _LIBCUDACXX_SEMAPHORE_MAX; + } + + _LIBCUDACXX_INLINE_VISIBILITY __sem_semaphore_base(ptrdiff_t __count = 0) + : __semaphore() +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER + , __frontbuffer(__count << 32) +# endif +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_BACK_BUFFER + , __backbuffer(0) +# endif + { + _LIBCUDACXX_ASSERT(__count <= max(), ""); + auto const __success = +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER + __libcpp_semaphore_init(&__semaphore, 0); +# else + __libcpp_semaphore_init(&__semaphore, __count); +# endif + _LIBCUDACXX_ASSERT(__success, ""); + } + + _LIBCUDACXX_INLINE_VISIBILITY ~__sem_semaphore_base() + { +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER + _LIBCUDACXX_ASSERT(0 == (__frontbuffer.load(memory_order_relaxed) & ~0u), ""); +# endif + auto const __success = __libcpp_semaphore_destroy(&__semaphore); + _LIBCUDACXX_ASSERT(__success, ""); + } + + __sem_semaphore_base(const __sem_semaphore_base&) = delete; + __sem_semaphore_base& operator=(const __sem_semaphore_base&) = delete; + + _LIBCUDACXX_INLINE_VISIBILITY void release(ptrdiff_t __update = 1) + { +# ifndef _LIBCUDACXX_HAS_NO_SEMAPHORE_FRONT_BUFFER + // boldly assume the semaphore is taken but uncontended + ptrdiff_t __old = 0; + // try to fast-release as long as it's uncontended + while (0 == (__old & ~0ul)) { - auto const current = max(Clock::now(), __abs_time); - return try_acquire_for(chrono::duration_cast(__abs_time - current)); + if (__frontbuffer.compare_exchange_weak(__old, __old + (__update << 32), memory_order_acq_rel)) + { + return; + } } - - template - _LIBCUDACXX_INLINE_VISIBILITY - bool try_acquire_for(chrono::duration const& __rel_time) +# endif + // slow-release it is + __release_slow(__update); + } + + _LIBCUDACXX_INLINE_VISIBILITY void acquire() + { + if (!__try_acquire_fast()) { - return __try_acquire_fast() || - __try_done(__libcpp_semaphore_wait_timed(&__semaphore, __rel_time)); + __try_done(__libcpp_semaphore_wait(&__semaphore)); } + } + + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire() noexcept + { + return try_acquire_for(chrono::nanoseconds(0)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire_until(chrono::time_point const& __abs_time) + { + auto const current = max(Clock::now(), __abs_time); + return try_acquire_for(chrono::duration_cast(__abs_time - current)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY bool try_acquire_for(chrono::duration const& __rel_time) + { + return __try_acquire_fast() || __try_done(__libcpp_semaphore_wait_timed(&__semaphore, __rel_time)); + } }; #endif //_LIBCUDACXX_HAS_NO_SEMAPHORES -template +template using __semaphore_base = #ifdef _LIBCUDACXX_USE_NATIVE_SEMAPHORES - __conditional_t<__least_max_value <= __sem_semaphore_base<_Sco>::max(), - __sem_semaphore_base<_Sco>, - __atomic_semaphore_base<_Sco, __least_max_value>> + __conditional_t<__least_max_value <= __sem_semaphore_base<_Sco>::max(), + __sem_semaphore_base<_Sco>, + __atomic_semaphore_base<_Sco, __least_max_value>> #else - __atomic_semaphore_base<_Sco, __least_max_value> + __atomic_semaphore_base<_Sco, __least_max_value> #endif - ; + ; -template +template class counting_semaphore : public __semaphore_base<__least_max_value, 0> { - static_assert(__least_max_value <= __semaphore_base<__least_max_value, 0>::max(), ""); + static_assert(__least_max_value <= __semaphore_base<__least_max_value, 0>::max(), ""); + public: - _LIBCUDACXX_INLINE_VISIBILITY constexpr - counting_semaphore(ptrdiff_t __count = 0) : __semaphore_base<__least_max_value, 0>(__count) { } - ~counting_semaphore() = default; + _LIBCUDACXX_INLINE_VISIBILITY constexpr counting_semaphore(ptrdiff_t __count = 0) + : __semaphore_base<__least_max_value, 0>(__count) + {} + ~counting_semaphore() = default; - counting_semaphore(const counting_semaphore&) = delete; - counting_semaphore& operator=(const counting_semaphore&) = delete; + counting_semaphore(const counting_semaphore&) = delete; + counting_semaphore& operator=(const counting_semaphore&) = delete; }; using binary_semaphore = counting_semaphore<1>; diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/span b/libcudacxx/include/cuda/std/detail/libcxx/include/span index 7e1e7a4172c..e8a46249e57 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/span +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/span @@ -138,7 +138,6 @@ template # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include #include @@ -167,9 +166,10 @@ template #include #include #include // for ptrdiff_t -#include +#include // all public C++ headers provide the assertion handler // standard-mandated includes +#include // [iterator.range] #include @@ -254,8 +254,8 @@ _LIBCUDACXX_INLINE_VAR constexpr bool __is_span_compatible_container< decltype(data(declval<_Tp>())), decltype(size(declval<_Tp>())), // remove_pointer_t(*)[] is convertible to ElementType(*)[] - enable_if_t< is_convertible()))> (*)[], _ElementType (*)[]>::value, - nullptr_t> >> = true; + enable_if_t()))> (*)[], _ElementType (*)[]>::value, + nullptr_t>>> = true; # endif // _CCCL_STD_VER <= 2014 || _CCCL_COMPILER_MSVC_2017 template @@ -340,8 +340,7 @@ public: _LIBCUDACXX_TEMPLATE(class _OtherElementType) _LIBCUDACXX_REQUIRES(__span_array_convertible) - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 - span(const array<_OtherElementType, _Extent>& __arr) noexcept + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data_{__arr.data()} {} @@ -578,8 +577,7 @@ public: _LIBCUDACXX_TEMPLATE(class _OtherElementType, size_t _Sz) _LIBCUDACXX_REQUIRES(__span_array_convertible) - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 - span(const array<_OtherElementType, _Sz>& __arr) noexcept + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX17 span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data_{__arr.data()} , __size_{_Sz} {} @@ -765,13 +763,13 @@ _CCCL_HOST_DEVICE span(array<_Tp, _Sz>&) -> span<_Tp, _Sz>; template _CCCL_HOST_DEVICE span(const array<_Tp, _Sz>&) -> span; -#if defined(_CCCL_COMPILER_MSVC_2017) -template +# if defined(_CCCL_COMPILER_MSVC_2017) +template _CCCL_HOST_DEVICE span(_Container&) -> span; -template +template _CCCL_HOST_DEVICE span(const _Container&) -> span; -#else // ^^^ _CCCL_COMPILER_MSVC_2017 ^^^ / vvv !_CCCL_COMPILER_MSVC_2017 vvv +# else // ^^^ _CCCL_COMPILER_MSVC_2017 ^^^ / vvv !_CCCL_COMPILER_MSVC_2017 vvv _LIBCUDACXX_TEMPLATE(class _It, class _EndOrSize) _LIBCUDACXX_REQUIRES(contiguous_iterator<_It>) _CCCL_HOST_DEVICE span(_It, _EndOrSize) -> span>>; @@ -779,7 +777,7 @@ _CCCL_HOST_DEVICE span(_It, _EndOrSize) -> span) _CCCL_HOST_DEVICE span(_Range&&) -> span>>; -#endif // !_CCCL_COMPILER_MSVC_2017 +# endif // !_CCCL_COMPILER_MSVC_2017 #endif // _CCCL_STD_VER >= 2017 diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/stdexcept b/libcudacxx/include/cuda/std/detail/libcxx/include/stdexcept index 743bc70570b..720862e0814 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/stdexcept +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/stdexcept @@ -53,9 +53,9 @@ public: # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include #include +#include // all public C++ headers provide the assertion handler #include #include diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/tuple b/libcudacxx/include/cuda/std/detail/libcxx/include/tuple index 198fa1eafd8..22cb1d51fe8 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/tuple +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/tuple @@ -155,9 +155,7 @@ template # pragma system_header #endif // no system header -#include // all public C++ headers provide the assertion handler #include -#include #include #include #include @@ -179,6 +177,8 @@ template #include #include #include +#include // all public C++ headers provide the assertion handler +#include #include #include @@ -187,38 +187,39 @@ template // [tuple.syn] #ifndef _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR -#include -#endif +# include +#endif // !_LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR #include _LIBCUDACXX_BEGIN_NAMESPACE_STD -template -struct __is_tuple_of_iterator_references : false_type +template +struct __is_tuple_of_iterator_references : false_type {}; // __tuple_leaf -struct __tuple_leaf_default_constructor_tag {}; +struct __tuple_leaf_default_constructor_tag +{}; -template ::value> +template ::value> class __tuple_leaf; template inline _LIBCUDACXX_INLINE_VISIBILITY void -swap(__tuple_leaf<_Ip, _Hp, _Ep> &__x, - __tuple_leaf<_Ip, _Hp, _Ep> - &__y) noexcept(__is_nothrow_swappable<_Hp>::value) { +swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable<_Hp>::value) +{ swap(__x.get(), __y.get()); } -template class __tuple_leaf { +template +class __tuple_leaf +{ _Hp __value_; template - _LIBCUDACXX_INLINE_VISIBILITY static constexpr bool __can_bind_reference() { + _LIBCUDACXX_INLINE_VISIBILITY static constexpr bool __can_bind_reference() + { #if __has_keyword(__reference_binds_to_temporary) return !__reference_binds_to_temporary(_Hp, _Tp); #else @@ -226,765 +227,719 @@ template class __tuple_leaf { #endif } - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf &operator=(const __tuple_leaf &); + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf& operator=(const __tuple_leaf&); public: _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_leaf() noexcept( - _LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Hp)) - : __value_() { - static_assert( - !_LIBCUDACXX_TRAIT(is_reference, _Hp), - "Attempted to default construct a reference element in a tuple"); + _LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Hp)) + : __value_() + { + static_assert(!_LIBCUDACXX_TRAIT(is_reference, _Hp), + "Attempted to default construct a reference element in a tuple"); } - _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_leaf( - __tuple_leaf_default_constructor_tag) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, - _Hp)) - : __value_() { - static_assert( - !_LIBCUDACXX_TRAIT(is_reference, _Hp), - "Attempted to default construct a reference element in a tuple"); + _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_leaf(__tuple_leaf_default_constructor_tag) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Hp)) + : __value_() + { + static_assert(!_LIBCUDACXX_TRAIT(is_reference, _Hp), + "Attempted to default construct a reference element in a tuple"); } template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, - const _Alloc &) - : __value_() { - static_assert( - !_LIBCUDACXX_TRAIT(is_reference, _Hp), - "Attempted to default construct a reference element in a tuple"); + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, const _Alloc&) + : __value_() + { + static_assert(!_LIBCUDACXX_TRAIT(is_reference, _Hp), + "Attempted to default construct a reference element in a tuple"); } template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, - const _Alloc &__a) - : __value_(allocator_arg_t(), __a) { - static_assert( - !_LIBCUDACXX_TRAIT(is_reference, _Hp), - "Attempted to default construct a reference element in a tuple"); + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, const _Alloc& __a) + : __value_(allocator_arg_t(), __a) + { + static_assert(!_LIBCUDACXX_TRAIT(is_reference, _Hp), + "Attempted to default construct a reference element in a tuple"); } template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, - const _Alloc &__a) - : __value_(__a) { - static_assert( - !_LIBCUDACXX_TRAIT(is_reference, _Hp), - "Attempted to default construct a reference element in a tuple"); + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, const _Alloc& __a) + : __value_(__a) + { + static_assert(!_LIBCUDACXX_TRAIT(is_reference, _Hp), + "Attempted to default construct a reference element in a tuple"); } template - using __can_forward = _And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, - is_constructible<_Hp, _Tp>>; + using __can_forward = _And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp>>; template ::value, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit __tuple_leaf( - _Tp &&__t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Hp, - _Tp)) - : __value_(_CUDA_VSTD::forward<_Tp>(__t)) { - static_assert(__can_bind_reference<_Tp &&>(), + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _Hp, _Tp)) + : __value_(_CUDA_VSTD::forward<_Tp>(__t)) + { + static_assert(__can_bind_reference<_Tp&&>(), "Attempted construction of reference element binds to a " "temporary whose lifetime has ended"); } template - _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, - const _Alloc &, _Tp &&__t) - : __value_(_CUDA_VSTD::forward<_Tp>(__t)) { - static_assert(__can_bind_reference<_Tp &&>(), + _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, const _Alloc&, _Tp&& __t) + : __value_(_CUDA_VSTD::forward<_Tp>(__t)) + { + static_assert(__can_bind_reference<_Tp&&>(), "Attempted construction of reference element binds to a " "temporary whose lifetime has ended"); } template - _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, - const _Alloc &__a, - _Tp &&__t) - : __value_(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tp>(__t)) { - static_assert( - !_LIBCUDACXX_TRAIT(is_reference, _Hp), - "Attempted to uses-allocator construct a reference element in a tuple"); + _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : __value_(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tp>(__t)) + { + static_assert(!_LIBCUDACXX_TRAIT(is_reference, _Hp), + "Attempted to uses-allocator construct a reference element in a tuple"); } template - _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, - const _Alloc &__a, - _Tp &&__t) - : __value_(_CUDA_VSTD::forward<_Tp>(__t), __a) { - static_assert( - !_LIBCUDACXX_TRAIT(is_reference, _Hp), - "Attempted to uses-allocator construct a reference element in a tuple"); + _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : __value_(_CUDA_VSTD::forward<_Tp>(__t), __a) + { + static_assert(!_LIBCUDACXX_TRAIT(is_reference, _Hp), + "Attempted to uses-allocator construct a reference element in a tuple"); } - __tuple_leaf(const __tuple_leaf &__t) = default; - __tuple_leaf(__tuple_leaf &&__t) = default; + __tuple_leaf(const __tuple_leaf& __t) = default; + __tuple_leaf(__tuple_leaf&& __t) = default; template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf &operator=(_Tp &&__t) noexcept( - _LIBCUDACXX_TRAIT(is_nothrow_assignable, _Hp &, _Tp)) { + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf& + operator=(_Tp&& __t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_assignable, _Hp&, _Tp)) + { __value_ = _CUDA_VSTD::forward<_Tp>(__t); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY int swap(__tuple_leaf &__t) noexcept( - __is_nothrow_swappable<__tuple_leaf>::value) { + _LIBCUDACXX_INLINE_VISIBILITY int swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable<__tuple_leaf>::value) + { _CUDA_VSTD::swap(*this, __t); return 0; } - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Hp & - get() noexcept { + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Hp& get() noexcept + { return __value_; } - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Hp & - get() const noexcept { + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Hp& get() const noexcept + { return __value_; } }; template -class __tuple_leaf<_Ip, _Hp, true> : private _Hp { - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf &operator=(const __tuple_leaf &); +class __tuple_leaf<_Ip, _Hp, true> : private _Hp +{ + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf& operator=(const __tuple_leaf&); public: - _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_leaf() noexcept( - is_nothrow_default_constructible<_Hp>::value) {} + _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) {} - _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_leaf( - __tuple_leaf_default_constructor_tag) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, - _Hp)) - : _Hp() {} + _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_leaf(__tuple_leaf_default_constructor_tag) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Hp)) + : _Hp() + {} template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, - const _Alloc &) {} + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, const _Alloc&) + {} template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, - const _Alloc &__a) - : _Hp(allocator_arg_t(), __a) {} + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, const _Alloc& __a) + : _Hp(allocator_arg_t(), __a) + {} template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, - const _Alloc &__a) - : _Hp(__a) {} + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf(integral_constant, const _Alloc& __a) + : _Hp(__a) + {} template - using __can_forward = _And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, - is_constructible<_Hp, _Tp>>; + using __can_forward = _And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp>>; template ::value, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit __tuple_leaf( - _Tp &&__t) noexcept((is_nothrow_constructible<_Hp, _Tp>::value)) - : _Hp(_CUDA_VSTD::forward<_Tp>(__t)) {} + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept( + (is_nothrow_constructible<_Hp, _Tp>::value)) + : _Hp(_CUDA_VSTD::forward<_Tp>(__t)) + {} template - _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, - const _Alloc &, _Tp &&__t) - : _Hp(_CUDA_VSTD::forward<_Tp>(__t)) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, const _Alloc&, _Tp&& __t) + : _Hp(_CUDA_VSTD::forward<_Tp>(__t)) + {} template - _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, - const _Alloc &__a, - _Tp &&__t) - : _Hp(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tp>(__t)) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : _Hp(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tp>(__t)) + {} template - _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, - const _Alloc &__a, - _Tp &&__t) - : _Hp(_CUDA_VSTD::forward<_Tp>(__t), __a) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : _Hp(_CUDA_VSTD::forward<_Tp>(__t), __a) + {} - __tuple_leaf(__tuple_leaf const &) = default; - __tuple_leaf(__tuple_leaf &&) = default; + __tuple_leaf(__tuple_leaf const&) = default; + __tuple_leaf(__tuple_leaf&&) = default; template - _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf &operator=(_Tp &&__t) noexcept( - _LIBCUDACXX_TRAIT(is_nothrow_assignable, _Hp &, _Tp)) { + _LIBCUDACXX_INLINE_VISIBILITY __tuple_leaf& + operator=(_Tp&& __t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_assignable, _Hp&, _Tp)) + { _Hp::operator=(_CUDA_VSTD::forward<_Tp>(__t)); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY int swap(__tuple_leaf &__t) noexcept( - __is_nothrow_swappable<__tuple_leaf>::value) { + _LIBCUDACXX_INLINE_VISIBILITY int swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable<__tuple_leaf>::value) + { _CUDA_VSTD::swap(*this, __t); return 0; } - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Hp & - get() noexcept { - return static_cast<_Hp &>(*this); + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 _Hp& get() noexcept + { + return static_cast<_Hp&>(*this); } - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Hp & - get() const noexcept { - return static_cast(*this); + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const _Hp& get() const noexcept + { + return static_cast(*this); } }; template -_LIBCUDACXX_INLINE_VISIBILITY void __swallow(_Tp &&...) noexcept {} +_LIBCUDACXX_INLINE_VISIBILITY void __swallow(_Tp&&...) noexcept +{} -template struct __all_default_constructible; +template +struct __all_default_constructible; template -struct __all_default_constructible<__tuple_types<_Tp...>> - : __all<_LIBCUDACXX_TRAIT(is_default_constructible, _Tp)...> {}; +struct __all_default_constructible<__tuple_types<_Tp...>> : __all<_LIBCUDACXX_TRAIT(is_default_constructible, _Tp)...> +{}; -struct __tuple_variadic_constructor_tag {}; +struct __tuple_variadic_constructor_tag +{}; // __tuple_impl -template struct __tuple_impl; +template +struct __tuple_impl; template -struct _LIBCUDACXX_DECLSPEC_EMPTY_BASES - __tuple_impl<__tuple_indices<_Indx...>, _Tp...> - : public __tuple_leaf<_Indx, _Tp>... { +struct _LIBCUDACXX_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...> + : public __tuple_leaf<_Indx, _Tp>... +{ _LIBCUDACXX_INLINE_VISIBILITY constexpr __tuple_impl() noexcept( - __all<_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, - _Tp)...>::value) {} + __all<_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Tp)...>::value) + {} // Handle non-allocator, full initialization // Old MSVC cannot handle the noexept specifier outside of template arguments template = 0, - bool __all_nothrow_constructible = __all<_LIBCUDACXX_TRAIT( - is_nothrow_constructible, _Tp, _Up)...>::value> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit __tuple_impl( - __tuple_variadic_constructor_tag, - _Up &&...__u) noexcept(__all_nothrow_constructible) - : __tuple_leaf<_Indx, _Tp>(_CUDA_VSTD::forward<_Up>(__u))... {} + bool __all_nothrow_constructible = __all<_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Up)...>::value> + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit __tuple_impl( + __tuple_variadic_constructor_tag, _Up&&... __u) noexcept(__all_nothrow_constructible) + : __tuple_leaf<_Indx, _Tp>(_CUDA_VSTD::forward<_Up>(__u))... + {} // Handle non-allocator, partial default initialization // Recursively delegate until we have full rank - template = 0> + template = 0> _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit __tuple_impl( - __tuple_variadic_constructor_tag __tag, - _Up &&...__u) noexcept(noexcept(__tuple_impl(__tag, - _CUDA_VSTD::forward<_Up>( - __u)..., - __tuple_leaf_default_constructor_tag{}))) - : __tuple_impl(__tag, _CUDA_VSTD::forward<_Up>(__u)..., - __tuple_leaf_default_constructor_tag{}) {} + __tuple_variadic_constructor_tag __tag, + _Up&&... __u) noexcept(noexcept(__tuple_impl(__tag, + _CUDA_VSTD::forward<_Up>(__u)..., + __tuple_leaf_default_constructor_tag{}))) + : __tuple_impl(__tag, _CUDA_VSTD::forward<_Up>(__u)..., __tuple_leaf_default_constructor_tag{}) + {} // Handle allocator aware, full initialization - template = 0> + template = 0> _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_impl( - allocator_arg_t, const _Alloc &__a, __tuple_variadic_constructor_tag, - _Up &&...__u) - : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Up>(), __a, - _CUDA_VSTD::forward<_Up>(__u))... {} + allocator_arg_t, const _Alloc& __a, __tuple_variadic_constructor_tag, _Up&&... __u) + : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Up>(), __a, _CUDA_VSTD::forward<_Up>(__u))... + {} // Handle allocator aware, full default initialization template - _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_impl(allocator_arg_t, - const _Alloc &__a) - : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc>(), __a)... {} + _LIBCUDACXX_INLINE_VISIBILITY explicit __tuple_impl(allocator_arg_t, const _Alloc& __a) + : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc>(), __a)... + {} template - using __tuple_elem_at = - __tuple_element_t<_Indx2, __make_tuple_types_t<_Tuple>>; + using __tuple_elem_at = __tuple_element_t<_Indx2, __make_tuple_types_t<_Tuple>>; - template >::value, - int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - __tuple_impl(_Tuple &&__t) noexcept( - (__all<_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, - __tuple_elem_at<_Tuple, _Indx>)...>::value)) - : __tuple_leaf<_Indx, _Tp>( - _CUDA_VSTD::forward<__tuple_elem_at<_Tuple, _Indx>>( - _CUDA_VSTD::get<_Indx>(__t)))... {} - - template >::value, - int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl(allocator_arg_t, const _Alloc &__a, - _Tuple &&__t) - : __tuple_leaf<_Indx, _Tp>( - __uses_alloc_ctor<_Tp, _Alloc, __tuple_elem_at<_Tuple, _Indx>>(), - __a, - _CUDA_VSTD::forward<__tuple_elem_at<_Tuple, _Indx>>( - _CUDA_VSTD::get<_Indx>(__t)))... {} - - template < - class _Tuple, - __enable_if_t<__tuple_assignable<_Tuple, tuple<_Tp...>>::value, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl &operator=(_Tuple &&__t) noexcept( - (__all<_LIBCUDACXX_TRAIT(is_nothrow_assignable, _Tp &, - __tuple_elem_at<_Tuple, _Indx>)...>::value)) { + template >::value, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __tuple_impl(_Tuple&& __t) noexcept( + (__all<_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, __tuple_elem_at<_Tuple, _Indx>)...>::value)) + : __tuple_leaf<_Indx, _Tp>(_CUDA_VSTD::forward<__tuple_elem_at<_Tuple, _Indx>>(_CUDA_VSTD::get<_Indx>(__t)))... + {} + + template >::value, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, __tuple_elem_at<_Tuple, _Indx>>(), + __a, + _CUDA_VSTD::forward<__tuple_elem_at<_Tuple, _Indx>>(_CUDA_VSTD::get<_Indx>(__t)))... + {} + + template >::value, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl& operator=(_Tuple&& __t) noexcept( + (__all<_LIBCUDACXX_TRAIT(is_nothrow_assignable, _Tp&, __tuple_elem_at<_Tuple, _Indx>)...>::value)) + { __swallow(__tuple_leaf<_Indx, _Tp>::operator=( - _CUDA_VSTD::forward<__tuple_elem_at<_Tuple, _Indx>>( - _CUDA_VSTD::get<_Indx>(__t)))...); + _CUDA_VSTD::forward<__tuple_elem_at<_Tuple, _Indx>>(_CUDA_VSTD::get<_Indx>(__t)))...); return *this; } - __tuple_impl(const __tuple_impl &) = default; - __tuple_impl(__tuple_impl &&) = default; + __tuple_impl(const __tuple_impl&) = default; + __tuple_impl(__tuple_impl&&) = default; - _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl & - operator=(const __tuple_impl &__t) noexcept( - (__all<_LIBCUDACXX_TRAIT(is_nothrow_copy_assignable, _Tp)...>::value)) { - __swallow(__tuple_leaf<_Indx, _Tp>::operator=( - static_cast &>(__t).get())...); + _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl& + operator=(const __tuple_impl& __t) noexcept((__all<_LIBCUDACXX_TRAIT(is_nothrow_copy_assignable, _Tp)...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast&>(__t).get())...); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl & - operator=(__tuple_impl &&__t) noexcept( - (__all<_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp)...>::value)) { - __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_CUDA_VSTD::forward<_Tp>( - static_cast<__tuple_leaf<_Indx, _Tp> &>(__t).get()))...); + _LIBCUDACXX_INLINE_VISIBILITY __tuple_impl& + operator=(__tuple_impl&& __t) noexcept((__all<_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp)...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=( + _CUDA_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY void swap(__tuple_impl &__t) noexcept( - __all<__is_nothrow_swappable<_Tp>::value...>::value) { - __swallow(__tuple_leaf<_Indx, _Tp>::swap( - static_cast<__tuple_leaf<_Indx, _Tp> &>(__t))...); + _LIBCUDACXX_INLINE_VISIBILITY void + swap(__tuple_impl& __t) noexcept(__all<__is_nothrow_swappable<_Tp>::value...>::value) + { + __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); } }; -struct __invalid_tuple_constraints { +struct __invalid_tuple_constraints +{ static constexpr bool __implicit_constructible = false; static constexpr bool __explicit_constructible = false; - static constexpr bool __nothrow_constructible = false; + static constexpr bool __nothrow_constructible = false; }; -template struct __tuple_constraints { +template +struct __tuple_constraints +{ static constexpr bool __implicit_default_constructible = - __all<__is_implicitly_default_constructible<_Tp>::value...>::value; + __all<__is_implicitly_default_constructible<_Tp>::value...>::value; static constexpr bool __explicit_default_constructible = - !__implicit_default_constructible && - __all<_LIBCUDACXX_TRAIT(is_default_constructible, _Tp)...>::value; + !__implicit_default_constructible && __all<_LIBCUDACXX_TRAIT(is_default_constructible, _Tp)...>::value; static constexpr bool __nothrow_default_constructible = - __all<_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Tp)...>::value; + __all<_LIBCUDACXX_TRAIT(is_nothrow_default_constructible, _Tp)...>::value; static constexpr bool __implicit_variadic_copy_constructible = - __tuple_constructible, tuple<_Tp...>>::value && - __tuple_convertible, tuple<_Tp...>>::value; + __tuple_constructible, tuple<_Tp...>>::value + && __tuple_convertible, tuple<_Tp...>>::value; static constexpr bool __explicit_variadic_copy_constructible = - __tuple_constructible, tuple<_Tp...>>::value && - !__tuple_convertible, tuple<_Tp...>>::value; + __tuple_constructible, tuple<_Tp...>>::value + && !__tuple_convertible, tuple<_Tp...>>::value; static constexpr bool __nothrow_variadic_copy_constructible = - __all<_LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Tp)...>::value; + __all<_LIBCUDACXX_TRAIT(is_nothrow_copy_constructible, _Tp)...>::value; - template struct _PackExpandsToThisTuple : false_type {}; + template + struct _PackExpandsToThisTuple : false_type + {}; template - struct _PackExpandsToThisTuple<_Arg> - : is_same<__remove_cvref_t<_Arg>, tuple<_Tp...>> {}; + struct _PackExpandsToThisTuple<_Arg> : is_same<__remove_cvref_t<_Arg>, tuple<_Tp...>> + {}; - template struct __variadic_constraints { + template + struct __variadic_constraints + { static constexpr bool __implicit_constructible = - __tuple_constructible, tuple<_Tp...>>::value && - __tuple_convertible, tuple<_Tp...>>::value; + __tuple_constructible, tuple<_Tp...>>::value + && __tuple_convertible, tuple<_Tp...>>::value; static constexpr bool __explicit_constructible = - __tuple_constructible, tuple<_Tp...>>::value && - !__tuple_convertible, tuple<_Tp...>>::value; + __tuple_constructible, tuple<_Tp...>>::value + && !__tuple_convertible, tuple<_Tp...>>::value; - static constexpr bool __nothrow_constructible = __all<_LIBCUDACXX_TRAIT( - is_nothrow_constructible, _Tp, _Args)...>::value; + static constexpr bool __nothrow_constructible = + __all<_LIBCUDACXX_TRAIT(is_nothrow_constructible, _Tp, _Args)...>::value; }; - template struct __variadic_constraints_less_rank { + template + struct __variadic_constraints_less_rank + { static constexpr bool __implicit_constructible = - __tuple_constructible< - tuple<_Args...>, - __make_tuple_types_t, sizeof...(_Args)>>::value && - __tuple_convertible< - tuple<_Args...>, - __make_tuple_types_t, sizeof...(_Args)>>::value && - __all_default_constructible<__make_tuple_types_t< - tuple<_Tp...>, sizeof...(_Tp), sizeof...(_Args)>>::value; + __tuple_constructible, __make_tuple_types_t, sizeof...(_Args)>>::value + && __tuple_convertible, __make_tuple_types_t, sizeof...(_Args)>>::value + && __all_default_constructible<__make_tuple_types_t, sizeof...(_Tp), sizeof...(_Args)>>::value; static constexpr bool __explicit_constructible = - __tuple_constructible< - tuple<_Args...>, - __make_tuple_types_t, sizeof...(_Args)>>::value && - !__tuple_convertible< - tuple<_Args...>, - __make_tuple_types_t, sizeof...(_Args)>>::value && - __all_default_constructible<__make_tuple_types_t< - tuple<_Tp...>, sizeof...(_Tp), sizeof...(_Args)>>::value; + __tuple_constructible, __make_tuple_types_t, sizeof...(_Args)>>::value + && !__tuple_convertible, __make_tuple_types_t, sizeof...(_Args)>>::value + && __all_default_constructible<__make_tuple_types_t, sizeof...(_Tp), sizeof...(_Args)>>::value; }; - template struct __valid_tuple_like_constraints { + template + struct __valid_tuple_like_constraints + { static constexpr bool __implicit_constructible = - __tuple_constructible<_Tuple, tuple<_Tp...>>::value && - __tuple_convertible<_Tuple, tuple<_Tp...>>::value; + __tuple_constructible<_Tuple, tuple<_Tp...>>::value && __tuple_convertible<_Tuple, tuple<_Tp...>>::value; static constexpr bool __explicit_constructible = - __tuple_constructible<_Tuple, tuple<_Tp...>>::value && - !__tuple_convertible<_Tuple, tuple<_Tp...>>::value; + __tuple_constructible<_Tuple, tuple<_Tp...>>::value && !__tuple_convertible<_Tuple, tuple<_Tp...>>::value; }; - template struct __valid_tuple_like_constraints_rank_one { + template + struct __valid_tuple_like_constraints_rank_one + { template struct _PreferTupleLikeConstructorImpl : _Or< - // Don't attempt the two checks below if the tuple we are given - // has the same type as this tuple. - _IsSame<__remove_cvref_t<_Tuple2>, tuple<_Tp...>>, - _Lazy<_And, _Not>, - _Not>>> {}; + // Don't attempt the two checks below if the tuple we are given + // has the same type as this tuple. + _IsSame<__remove_cvref_t<_Tuple2>, tuple<_Tp...>>, + _Lazy<_And, _Not>, _Not>>> + {}; // This trait is used to disable the tuple-like constructor when // the UTypes... constructor should be selected instead. // See LWG issue #2549. template - using _PreferTupleLikeConstructor = - _PreferTupleLikeConstructorImpl<_Tuple2>; + using _PreferTupleLikeConstructor = _PreferTupleLikeConstructorImpl<_Tuple2>; static constexpr bool __implicit_constructible = - __tuple_constructible<_Tuple, tuple<_Tp...>>::value && - __tuple_convertible<_Tuple, tuple<_Tp...>>::value && - _PreferTupleLikeConstructor<_Tuple>::value; + __tuple_constructible<_Tuple, tuple<_Tp...>>::value && __tuple_convertible<_Tuple, tuple<_Tp...>>::value + && _PreferTupleLikeConstructor<_Tuple>::value; static constexpr bool __explicit_constructible = - __tuple_constructible<_Tuple, tuple<_Tp...>>::value && - !__tuple_convertible<_Tuple, tuple<_Tp...>>::value && - _PreferTupleLikeConstructor<_Tuple>::value; + __tuple_constructible<_Tuple, tuple<_Tp...>>::value && !__tuple_convertible<_Tuple, tuple<_Tp...>>::value + && _PreferTupleLikeConstructor<_Tuple>::value; }; template using __tuple_like_constraints = - _If, - __valid_tuple_like_constraints<_Tuple>>; + _If, __valid_tuple_like_constraints<_Tuple>>; }; -template class _LIBCUDACXX_TEMPLATE_VIS tuple { +template +class _LIBCUDACXX_TEMPLATE_VIS tuple +{ typedef __tuple_impl<__make_tuple_indices_t, _Tp...> _BaseT; _BaseT __base_; - template struct _PackExpandsToThisTuple : false_type {}; + template + struct _PackExpandsToThisTuple : false_type + {}; template - struct _PackExpandsToThisTuple<_Arg> - : is_same<__remove_cvref_t<_Arg>, tuple> {}; + struct _PackExpandsToThisTuple<_Arg> : is_same<__remove_cvref_t<_Arg>, tuple> + {}; public: template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __tuple_element_t<_Ip, tuple>& - __get_impl() & noexcept + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __tuple_element_t<_Ip, tuple>& __get_impl() & noexcept { typedef _LIBCUDACXX_NODEBUG_TYPE __tuple_element_t<_Ip, tuple> type; return static_cast<__tuple_leaf<_Ip, type>&>(__base_).get(); } template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const __tuple_element_t<_Ip, tuple>& - __get_impl() const& noexcept + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const __tuple_element_t<_Ip, tuple>& __get_impl() const& noexcept { typedef _LIBCUDACXX_NODEBUG_TYPE __tuple_element_t<_Ip, tuple> type; return static_cast&>(__base_).get(); } template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __tuple_element_t<_Ip, tuple>&& - __get_impl() && noexcept + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 __tuple_element_t<_Ip, tuple>&& __get_impl() && noexcept { typedef _LIBCUDACXX_NODEBUG_TYPE __tuple_element_t<_Ip, tuple> type; return static_cast(static_cast<__tuple_leaf<_Ip, type>&&>(__base_).get()); } template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const __tuple_element_t<_Ip, tuple>&& - __get_impl() const&& noexcept + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const __tuple_element_t<_Ip, tuple>&& __get_impl() const&& noexcept { typedef _LIBCUDACXX_NODEBUG_TYPE __tuple_element_t<_Ip, tuple> type; return static_cast(static_cast&&>(__base_).get()); } - template < class _Constraints = __tuple_constraints<_Tp...>, - __enable_if_t<_Constraints::__implicit_default_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY constexpr tuple() noexcept( - _Constraints::__nothrow_default_constructible) {} - - template < - class _Constraints = __tuple_constraints<_Tp...>, - __enable_if_t<_Constraints::__explicit_default_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY explicit constexpr tuple() noexcept( - _Constraints::__nothrow_default_constructible) {} - - tuple(tuple const &) = default; - tuple(tuple &&) = default; - - template < - class _AllocArgT, class _Alloc, - class _Constraints = __tuple_constraints<_Tp...>, - __enable_if_t<_LIBCUDACXX_TRAIT(is_same, allocator_arg_t, _AllocArgT), - int> = 0, - __enable_if_t<_Constraints::__implicit_default_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY tuple(_AllocArgT, _Alloc const &__a) noexcept( - _Constraints::__nothrow_default_constructible) - : __base_(allocator_arg_t(), __a) {} - - template < - class _AllocArgT, class _Alloc, - class _Constraints = __tuple_constraints<_Tp...>, - __enable_if_t<_LIBCUDACXX_TRAIT(is_same, allocator_arg_t, _AllocArgT), - int> = 0, - __enable_if_t<_Constraints::__explicit_default_constructible, int> = 0> - explicit _LIBCUDACXX_INLINE_VISIBILITY tuple( - _AllocArgT, - _Alloc const &__a) noexcept(_Constraints::__nothrow_default_constructible) - : __base_(allocator_arg_t(), __a) {} - - template , - __enable_if_t<_Constraints::__implicit_variadic_copy_constructible, - int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - tuple(const _Tp &...__t) noexcept( - _Constraints::__nothrow_variadic_copy_constructible) - : __base_(__tuple_variadic_constructor_tag{}, __t...) {} + template , + __enable_if_t<_Constraints::__implicit_default_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY constexpr tuple() noexcept(_Constraints::__nothrow_default_constructible) + {} - template , - __enable_if_t<_Constraints::__explicit_variadic_copy_constructible, - int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit tuple( - const _Tp &...__t) noexcept(_Constraints:: - __nothrow_variadic_copy_constructible) - : __base_(__tuple_variadic_constructor_tag{}, __t...) {} - - template , - __enable_if_t<_Constraints::__implicit_variadic_copy_constructible, - int> = 0> + template , + __enable_if_t<_Constraints::__explicit_default_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY explicit constexpr tuple() noexcept(_Constraints::__nothrow_default_constructible) + {} + + tuple(tuple const&) = default; + tuple(tuple&&) = default; + + template , + __enable_if_t<_LIBCUDACXX_TRAIT(is_same, allocator_arg_t, _AllocArgT), int> = 0, + __enable_if_t<_Constraints::__implicit_default_constructible, int> = 0> _LIBCUDACXX_INLINE_VISIBILITY - tuple(allocator_arg_t, const _Alloc &__a, const _Tp &...__t) noexcept( - _Constraints::__nothrow_variadic_copy_constructible) - : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, - __t...) {} - - template , - __enable_if_t<_Constraints::__explicit_variadic_copy_constructible, - int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY explicit tuple( - allocator_arg_t, const _Alloc &__a, - const _Tp - &...__t) noexcept(_Constraints::__nothrow_variadic_copy_constructible) - : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, - __t...) {} + tuple(_AllocArgT, _Alloc const& __a) noexcept(_Constraints::__nothrow_default_constructible) + : __base_(allocator_arg_t(), __a) + {} + + template , + __enable_if_t<_LIBCUDACXX_TRAIT(is_same, allocator_arg_t, _AllocArgT), int> = 0, + __enable_if_t<_Constraints::__explicit_default_constructible, int> = 0> + explicit _LIBCUDACXX_INLINE_VISIBILITY + tuple(_AllocArgT, _Alloc const& __a) noexcept(_Constraints::__nothrow_default_constructible) + : __base_(allocator_arg_t(), __a) + {} + + template , + __enable_if_t<_Constraints::__implicit_variadic_copy_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 + tuple(const _Tp&... __t) noexcept(_Constraints::__nothrow_variadic_copy_constructible) + : __base_(__tuple_variadic_constructor_tag{}, __t...) + {} + + template , + __enable_if_t<_Constraints::__explicit_variadic_copy_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit tuple(const _Tp&... __t) noexcept( + _Constraints::__nothrow_variadic_copy_constructible) + : __base_(__tuple_variadic_constructor_tag{}, __t...) + {} + + template , + __enable_if_t<_Constraints::__implicit_variadic_copy_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t) noexcept( + _Constraints::__nothrow_variadic_copy_constructible) + : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, __t...) + {} + + template , + __enable_if_t<_Constraints::__explicit_variadic_copy_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY explicit tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t) noexcept( + _Constraints::__nothrow_variadic_copy_constructible) + : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, __t...) + {} #if defined(_LIBCUDACXX_NO_TUPLE_NOEXCEPT) - template using __base_noexcept_constructible = false_type; + template + using __base_noexcept_constructible = false_type; #else template - using __base_noexcept_constructible = - is_nothrow_constructible<_BaseT, _Vp...>; + using __base_noexcept_constructible = is_nothrow_constructible<_BaseT, _Vp...>; #endif // defined(_LIBCUDACXX_NO_TUPLE_NOEXCEPT) template using __variadic_constraints = - _If::value && - sizeof...(_Up) == sizeof...(_Tp), - typename __tuple_constraints<_Tp...>::template __variadic_constraints< - _Up...>, - __invalid_tuple_constraints>; + _If::value && sizeof...(_Up) == sizeof...(_Tp), + typename __tuple_constraints<_Tp...>::template __variadic_constraints<_Up...>, + __invalid_tuple_constraints>; - template , + template , __enable_if_t<_Constraints::__implicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - tuple(_Up &&...__u) noexcept(_Constraints::__nothrow_constructible) - : __base_(__tuple_variadic_constructor_tag{}, - _CUDA_VSTD::forward<_Up>(__u)...) {} + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 tuple(_Up&&... __u) noexcept(_Constraints::__nothrow_constructible) + : __base_(__tuple_variadic_constructor_tag{}, _CUDA_VSTD::forward<_Up>(__u)...) + {} - template , + template , __enable_if_t<_Constraints::__explicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit tuple(_Up &&...__u) noexcept( - _Constraints::__nothrow_constructible) - : __base_(__tuple_variadic_constructor_tag{}, - _CUDA_VSTD::forward<_Up>(__u)...) {} + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit tuple(_Up&&... __u) noexcept( + _Constraints::__nothrow_constructible) + : __base_(__tuple_variadic_constructor_tag{}, _CUDA_VSTD::forward<_Up>(__u)...) + {} template using __variadic_constraints_less_rank = - _If::value, - typename __tuple_constraints< - _Tp...>::template __variadic_constraints_less_rank<_Up...>, - __invalid_tuple_constraints>; + _If::value, + typename __tuple_constraints<_Tp...>::template __variadic_constraints_less_rank<_Up...>, + __invalid_tuple_constraints>; template , - __enable_if_t = 0, + class _Constraints = __variadic_constraints_less_rank<_Up...>, + __enable_if_t = 0, __enable_if_t<_Constraints::__implicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit tuple(_Up &&...__u) noexcept( - __base_noexcept_constructible<__tuple_variadic_constructor_tag, - _Up...>::value) - : __base_(__tuple_variadic_constructor_tag{}, - _CUDA_VSTD::forward<_Up>(__u)...) {} - - template , + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit tuple(_Up&&... __u) noexcept( + __base_noexcept_constructible<__tuple_variadic_constructor_tag, _Up...>::value) + : __base_(__tuple_variadic_constructor_tag{}, _CUDA_VSTD::forward<_Up>(__u)...) + {} + + template , __enable_if_t<_Constraints::__implicit_constructible, int> = 0> _LIBCUDACXX_INLINE_VISIBILITY - tuple(allocator_arg_t, const _Alloc &__a, - _Up &&...__u) noexcept(_Constraints::__nothrow_constructible) - : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, - _CUDA_VSTD::forward<_Up>(__u)...) {} + tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) noexcept(_Constraints::__nothrow_constructible) + : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, _CUDA_VSTD::forward<_Up>(__u)...) + {} - template , + template , __enable_if_t<_Constraints::__explicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY explicit tuple( - allocator_arg_t, const _Alloc &__a, - _Up &&...__u) noexcept(_Constraints::__nothrow_constructible) - : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, - _CUDA_VSTD::forward<_Up>(__u)...) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) noexcept( + _Constraints::__nothrow_constructible) + : __base_(allocator_arg_t(), __a, __tuple_variadic_constructor_tag{}, _CUDA_VSTD::forward<_Up>(__u)...) + {} template using __tuple_like_constraints = - _If<__tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value, - typename __tuple_constraints< - _Tp...>::template __tuple_like_constraints<_Tuple>, - __invalid_tuple_constraints>; + _If<__tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value, + typename __tuple_constraints<_Tp...>::template __tuple_like_constraints<_Tuple>, + __invalid_tuple_constraints>; // Horrible hack to make tuple_of_iterator_references work template ::value, int> = 0, - __enable_if_t<(tuple_size<_TupleOfIteratorReferences>::value == sizeof...(_Tp)), int> = 0> + __enable_if_t<(tuple_size<_TupleOfIteratorReferences>::value == sizeof...(_Tp)), int> = 0> _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 tuple(_TupleOfIteratorReferences&& __t) : tuple(_CUDA_VSTD::forward<_TupleOfIteratorReferences>(__t).template __to_tuple<_Tp...>( __make_tuple_indices_t())) {} - template < - class _Tuple, class _Constraints = __tuple_like_constraints<_Tuple>, - __enable_if_t::value, int> = 0, - __enable_if_t = 0, - __enable_if_t<_Constraints::__implicit_constructible, int> = 0> + template , + __enable_if_t::value, int> = 0, + __enable_if_t = 0, + __enable_if_t<_Constraints::__implicit_constructible, int> = 0> _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - tuple(_Tuple &&__t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, - _BaseT, _Tuple)) - : __base_(_CUDA_VSTD::forward<_Tuple>(__t)) {} + tuple(_Tuple&& __t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _BaseT, _Tuple)) + : __base_(_CUDA_VSTD::forward<_Tuple>(__t)) + {} template , + class _Constraints = __tuple_like_constraints, __enable_if_t::value, int> = 0, - __enable_if_t<_Constraints::__implicit_constructible, int> = 0> + __enable_if_t<_Constraints::__implicit_constructible, int> = 0> _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - tuple(const _Tuple &__t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, - _BaseT, const _Tuple &)) - : __base_(__t) {} - - template < - class _Tuple, class _Constraints = __tuple_like_constraints<_Tuple>, - __enable_if_t::value, int> = 0, - __enable_if_t = 0, - __enable_if_t<_Constraints::__explicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit tuple(_Tuple &&__t) noexcept( - _LIBCUDACXX_TRAIT(is_nothrow_constructible, _BaseT, _Tuple)) - : __base_(_CUDA_VSTD::forward<_Tuple>(__t)) {} + tuple(const _Tuple& __t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _BaseT, const _Tuple&)) + : __base_(__t) + {} template , + class _Constraints = __tuple_like_constraints<_Tuple>, + __enable_if_t::value, int> = 0, + __enable_if_t = 0, + __enable_if_t<_Constraints::__explicit_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit tuple(_Tuple&& __t) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _BaseT, _Tuple)) + : __base_(_CUDA_VSTD::forward<_Tuple>(__t)) + {} + + template , __enable_if_t::value, int> = 0, - __enable_if_t<_Constraints::__explicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 explicit tuple( - const _Tuple - &__t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_constructible, _BaseT, - const _Tuple &)) - : __base_(__t) {} - - template , + __enable_if_t<_Constraints::__explicit_constructible, int> = 0> + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 explicit tuple(const _Tuple& __t) noexcept( + _LIBCUDACXX_TRAIT(is_nothrow_constructible, _BaseT, const _Tuple&)) + : __base_(__t) + {} + + template , __enable_if_t<_Constraints::__implicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc &__a, - _Tuple &&__t) - : __base_(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tuple>(__t)) {} + _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : __base_(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tuple>(__t)) + {} - template , + template , __enable_if_t<_Constraints::__explicit_constructible, int> = 0> - _LIBCUDACXX_INLINE_VISIBILITY explicit tuple(allocator_arg_t, - const _Alloc &__a, _Tuple &&__t) - : __base_(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tuple>(__t)) {} + _LIBCUDACXX_INLINE_VISIBILITY explicit tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : __base_(allocator_arg_t(), __a, _CUDA_VSTD::forward<_Tuple>(__t)) + {} using _CanCopyAssign = __all<_LIBCUDACXX_TRAIT(is_copy_assignable, _Tp)...>; using _CanMoveAssign = __all<_LIBCUDACXX_TRAIT(is_move_assignable, _Tp)...>; - _LIBCUDACXX_INLINE_VISIBILITY tuple &operator=( - __conditional_t<_CanCopyAssign::value, tuple, __nat> const - &__t) noexcept((__all<_LIBCUDACXX_TRAIT(is_nothrow_copy_assignable, - _Tp)...>::value)) { + _LIBCUDACXX_INLINE_VISIBILITY tuple& + operator=(__conditional_t<_CanCopyAssign::value, tuple, __nat> const& __t) noexcept( + (__all<_LIBCUDACXX_TRAIT(is_nothrow_copy_assignable, _Tp)...>::value)) + { __base_.operator=(__t.__base_); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY tuple &operator=( - __conditional_t<_CanMoveAssign::value, tuple, __nat> - &&__t) noexcept((__all<_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, - _Tp)...>::value)) { - __base_.operator=(static_cast<_BaseT &&>(__t.__base_)); + _LIBCUDACXX_INLINE_VISIBILITY tuple& operator=(__conditional_t<_CanMoveAssign::value, tuple, __nat>&& __t) noexcept( + (__all<_LIBCUDACXX_TRAIT(is_nothrow_move_assignable, _Tp)...>::value)) + { + __base_.operator=(static_cast<_BaseT&&>(__t.__base_)); return *this; } - template < - class _Tuple, - __enable_if_t<__tuple_assignable<_Tuple, tuple>::value, bool> = false> - _LIBCUDACXX_INLINE_VISIBILITY tuple &operator=(_Tuple &&__t) noexcept( - _LIBCUDACXX_TRAIT(is_nothrow_assignable, _BaseT &, _Tuple)) { + template ::value, bool> = false> + _LIBCUDACXX_INLINE_VISIBILITY tuple& + operator=(_Tuple&& __t) noexcept(_LIBCUDACXX_TRAIT(is_nothrow_assignable, _BaseT&, _Tuple)) + { __base_.operator=(_CUDA_VSTD::forward<_Tuple>(__t)); return *this; } - _LIBCUDACXX_INLINE_VISIBILITY void swap(tuple &__t) noexcept( - __all<__is_nothrow_swappable<_Tp>::value...>::value) { + _LIBCUDACXX_INLINE_VISIBILITY void swap(tuple& __t) noexcept(__all<__is_nothrow_swappable<_Tp>::value...>::value) + { __base_.swap(__t.__base_); } }; -template <> class _LIBCUDACXX_TEMPLATE_VIS tuple<> { +template <> +class _LIBCUDACXX_TEMPLATE_VIS tuple<> +{ public: constexpr tuple() noexcept = default; template - _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, - const _Alloc &) noexcept {} + _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc&) noexcept + {} template - _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc &, - const tuple &) noexcept {} + _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc&, const tuple&) noexcept + {} template - _LIBCUDACXX_INLINE_VISIBILITY tuple(array<_Up, 0>) noexcept {} + _LIBCUDACXX_INLINE_VISIBILITY tuple(array<_Up, 0>) noexcept + {} template - _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc &, - array<_Up, 0>) noexcept {} - _LIBCUDACXX_INLINE_VISIBILITY void swap(tuple &) noexcept {} + _LIBCUDACXX_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) noexcept + {} + _LIBCUDACXX_INLINE_VISIBILITY void swap(tuple&) noexcept {} }; #ifndef _LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES -template _CCCL_HOST_DEVICE tuple(_Tp...) -> tuple<_Tp...>; +template +_CCCL_HOST_DEVICE tuple(_Tp...) -> tuple<_Tp...>; template _CCCL_HOST_DEVICE tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>; template _CCCL_HOST_DEVICE tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>; template -_CCCL_HOST_DEVICE tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) - -> tuple<_Tp1, _Tp2>; +_CCCL_HOST_DEVICE tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>; template -_CCCL_HOST_DEVICE tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) - -> tuple<_Tp...>; +_CCCL_HOST_DEVICE tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>; #endif // _LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES template -inline _LIBCUDACXX_INLINE_VISIBILITY - __enable_if_t<_And<__is_swappable<_Tp>...>::value, void> - swap(tuple<_Tp...> &__t, tuple<_Tp...> &__u) noexcept( - __all<__is_nothrow_swappable<_Tp>::value...>::value) { +inline _LIBCUDACXX_INLINE_VISIBILITY __enable_if_t<_And<__is_swappable<_Tp>...>::value, void> +swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) noexcept(__all<__is_nothrow_swappable<_Tp>::value...>::value) +{ __t.swap(__u); } @@ -1019,67 +974,66 @@ get(const tuple<_Tp...>&& __t) noexcept #if _CCCL_STD_VER > 2011 -namespace __find_detail { +namespace __find_detail +{ static constexpr size_t __not_found = ~size_t(0); static constexpr size_t __ambiguous = __not_found - 1; -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr size_t -__find_idx_return(size_t __curr_i, size_t __res, bool __matches) { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) +{ return !__matches ? __res : (__res == __not_found ? __curr_i : __ambiguous); } template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr size_t -__find_idx(size_t __i, const bool (&__matches)[_Nx]) { - return __i == _Nx ? __not_found - : __find_idx_return(__i, __find_idx(__i + 1, __matches), - __matches[__i]); +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) +{ + return __i == _Nx ? __not_found : __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]); } -template struct __find_exactly_one_checked { - static constexpr bool __matches[sizeof...(_Args)] = { - is_same<_T1, _Args>::value...}; - static constexpr size_t value = __find_detail::__find_idx(0, __matches); +template +struct __find_exactly_one_checked +{ + static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...}; + static constexpr size_t value = __find_detail::__find_idx(0, __matches); static_assert(value != __not_found, "type not found in type list"); - static_assert(value != __ambiguous, - "type occurs more than once in type list"); + static_assert(value != __ambiguous, "type occurs more than once in type list"); }; -template struct __find_exactly_one_checked<_T1> { +template +struct __find_exactly_one_checked<_T1> +{ static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); }; } // namespace __find_detail template -struct __find_exactly_one_t - : public __find_detail::__find_exactly_one_checked<_T1, _Args...> {}; +struct __find_exactly_one_t : public __find_detail::__find_exactly_one_checked<_T1, _Args...> +{}; template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1 & -get(tuple<_Args...> &__tup) noexcept { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1& get(tuple<_Args...>& __tup) noexcept +{ return _CUDA_VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); } template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1 const & -get(tuple<_Args...> const &__tup) noexcept { +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept +{ return _CUDA_VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); } template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1 && -get(tuple<_Args...> &&__tup) noexcept { - return _CUDA_VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>( - _CUDA_VSTD::move(__tup)); +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept +{ + return _CUDA_VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_CUDA_VSTD::move(__tup)); } template -inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1 const && -get(tuple<_Args...> const &&__tup) noexcept { - return _CUDA_VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>( - _CUDA_VSTD::move(__tup)); +inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept +{ + return _CUDA_VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_CUDA_VSTD::move(__tup)); } #endif @@ -1087,163 +1041,179 @@ get(tuple<_Args...> const &&__tup) noexcept { // tie template -inline _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 tuple<_Tp &...> - tie(_Tp &...__t) noexcept { - return tuple<_Tp &...>(__t...); +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 tuple<_Tp&...> tie(_Tp&... __t) noexcept +{ + return tuple<_Tp&...>(__t...); } -template struct __ignore_t { +template +struct __ignore_t +{ template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const - __ignore_t & - operator=(_Tp &&) const { + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 const __ignore_t& operator=(_Tp&&) const + { return *this; } }; -namespace { - _LIBCUDACXX_CPO_ACCESSIBILITY __ignore_t ignore{}; +namespace +{ +_LIBCUDACXX_CPO_ACCESSIBILITY __ignore_t ignore{}; } // namespace template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - tuple::type...> - make_tuple(_Tp &&...__t) { - return tuple::type...>( - _CUDA_VSTD::forward<_Tp>(__t)...); +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 tuple::type...> +make_tuple(_Tp&&... __t) +{ + return tuple::type...>(_CUDA_VSTD::forward<_Tp>(__t)...); } template -inline _LIBCUDACXX_INLINE_VISIBILITY - _CCCL_CONSTEXPR_CXX14 tuple<_Tp &&...> - forward_as_tuple(_Tp &&...__t) noexcept { - return tuple<_Tp &&...>(_CUDA_VSTD::forward<_Tp>(__t)...); +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 tuple<_Tp&&...> forward_as_tuple(_Tp&&... __t) noexcept +{ + return tuple<_Tp&&...>(_CUDA_VSTD::forward<_Tp>(__t)...); } -template struct __tuple_equal { +template +struct __tuple_equal +{ template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool - operator()(const _Tp &__x, const _Up &__y) { - return __tuple_equal<_Ip - 1>()(__x, __y) && - _CUDA_VSTD::get<_Ip - 1>(__x) == _CUDA_VSTD::get<_Ip - 1>(__y); + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator()(const _Tp& __x, const _Up& __y) + { + return __tuple_equal<_Ip - 1>()(__x, __y) && _CUDA_VSTD::get<_Ip - 1>(__x) == _CUDA_VSTD::get<_Ip - 1>(__y); } }; -template <> struct __tuple_equal<0> { +template <> +struct __tuple_equal<0> +{ template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool - operator()(const _Tp &, const _Up &) { + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator()(const _Tp&, const _Up&) + { return true; } }; template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool -operator==(const tuple<_Tp...> &__x, const tuple<_Up...> &__y) { - static_assert(sizeof...(_Tp) == sizeof...(_Up), - "Can't compare tuples of different sizes"); +operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); return __tuple_equal()(__x, __y); } template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool -operator!=(const tuple<_Tp...> &__x, const tuple<_Up...> &__y) { +operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ return !(__x == __y); } -template struct __tuple_less { +template +struct __tuple_less +{ template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool - operator()(const _Tp &__x, const _Up &__y) { + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator()(const _Tp& __x, const _Up& __y) + { const size_t __idx = tuple_size<_Tp>::value - _Ip; - if (_CUDA_VSTD::get<__idx>(__x) < _CUDA_VSTD::get<__idx>(__y)) { + if (_CUDA_VSTD::get<__idx>(__x) < _CUDA_VSTD::get<__idx>(__y)) + { return true; } - if (_CUDA_VSTD::get<__idx>(__y) < _CUDA_VSTD::get<__idx>(__x)) { + if (_CUDA_VSTD::get<__idx>(__y) < _CUDA_VSTD::get<__idx>(__x)) + { return false; } return __tuple_less<_Ip - 1>()(__x, __y); } }; -template <> struct __tuple_less<0> { +template <> +struct __tuple_less<0> +{ template - _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool - operator()(const _Tp &, const _Up &) { + _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool operator()(const _Tp&, const _Up&) + { return false; } }; template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool -operator<(const tuple<_Tp...> &__x, const tuple<_Up...> &__y) { - static_assert(sizeof...(_Tp) == sizeof...(_Up), - "Can't compare tuples of different sizes"); +operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); return __tuple_less()(__x, __y); } template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool -operator>(const tuple<_Tp...> &__x, const tuple<_Up...> &__y) { +operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ return __y < __x; } template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool -operator>=(const tuple<_Tp...> &__x, const tuple<_Up...> &__y) { +operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ return !(__x < __y); } template inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 bool -operator<=(const tuple<_Tp...> &__x, const tuple<_Up...> &__y) { +operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ return !(__y < __x); } // tuple_cat -template struct __tuple_cat_type; +template +struct __tuple_cat_type; template -struct __tuple_cat_type, __tuple_types<_Utypes...>> { +struct __tuple_cat_type, __tuple_types<_Utypes...>> +{ typedef _LIBCUDACXX_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type; }; template -struct __tuple_cat_return_1 {}; +struct __tuple_cat_return_1 +{}; template -struct __tuple_cat_return_1, true, _Tuple0> { - typedef _LIBCUDACXX_NODEBUG_TYPE typename __tuple_cat_type< - tuple<_Types...>, __make_tuple_types_t<__remove_cvref_t<_Tuple0>>>::type - type; +struct __tuple_cat_return_1, true, _Tuple0> +{ + typedef _LIBCUDACXX_NODEBUG_TYPE + typename __tuple_cat_type, __make_tuple_types_t<__remove_cvref_t<_Tuple0>>>::type type; }; template -struct __tuple_cat_return_1, true, _Tuple0, _Tuple1, - _Tuples...> +struct __tuple_cat_return_1, true, _Tuple0, _Tuple1, _Tuples...> : public __tuple_cat_return_1< - typename __tuple_cat_type< - tuple<_Types...>, - __make_tuple_types_t<__remove_cvref_t<_Tuple0>>>::type, - __tuple_like<__libcpp_remove_reference_t<_Tuple1>>::value, _Tuple1, - _Tuples...> {}; + typename __tuple_cat_type, __make_tuple_types_t<__remove_cvref_t<_Tuple0>>>::type, + __tuple_like<__libcpp_remove_reference_t<_Tuple1>>::value, + _Tuple1, + _Tuples...> +{}; -template struct __tuple_cat_return; +template +struct __tuple_cat_return; template struct __tuple_cat_return<_Tuple0, _Tuples...> - : public __tuple_cat_return_1< - tuple<>, __tuple_like<__libcpp_remove_reference_t<_Tuple0>>::value, - _Tuple0, _Tuples...> {}; + : public __tuple_cat_return_1, __tuple_like<__libcpp_remove_reference_t<_Tuple0>>::value, _Tuple0, _Tuples...> +{}; -template <> struct __tuple_cat_return<> { +template <> +struct __tuple_cat_return<> +{ typedef _LIBCUDACXX_NODEBUG_TYPE tuple<> type; }; -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 tuple<> -tuple_cat() { +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 tuple<> tuple_cat() +{ return tuple<>(); } @@ -1251,87 +1221,76 @@ template struct __tuple_cat_return_ref_imp; template -struct __tuple_cat_return_ref_imp, __tuple_indices<_I0...>, - _Tuple0> { +struct __tuple_cat_return_ref_imp, __tuple_indices<_I0...>, _Tuple0> +{ typedef _LIBCUDACXX_NODEBUG_TYPE __libcpp_remove_reference_t<_Tuple0> _T0; - typedef tuple< - _Types..., - typename __apply_cv<_Tuple0, __tuple_element_t<_I0, _T0>>::type &&...> - type; + typedef tuple<_Types..., typename __apply_cv<_Tuple0, __tuple_element_t<_I0, _T0>>::type&&...> type; }; -template -struct __tuple_cat_return_ref_imp, __tuple_indices<_I0...>, - _Tuple0, _Tuple1, _Tuples...> +template +struct __tuple_cat_return_ref_imp, __tuple_indices<_I0...>, _Tuple0, _Tuple1, _Tuples...> : public __tuple_cat_return_ref_imp< - tuple<_Types..., - typename __apply_cv< - _Tuple0, __tuple_element_t<_I0, __libcpp_remove_reference_t< - _Tuple0>>>::type &&...>, - __make_tuple_indices_t< - tuple_size<__libcpp_remove_reference_t<_Tuple1>>::value>, - _Tuple1, _Tuples...> {}; + tuple<_Types..., + typename __apply_cv<_Tuple0, __tuple_element_t<_I0, __libcpp_remove_reference_t<_Tuple0>>>::type&&...>, + __make_tuple_indices_t>::value>, + _Tuple1, + _Tuples...> +{}; template struct __tuple_cat_return_ref - : public __tuple_cat_return_ref_imp< - tuple<>, - __make_tuple_indices_t< - tuple_size<__libcpp_remove_reference_t<_Tuple0>>::value>, - _Tuple0, _Tuples...> {}; + : public __tuple_cat_return_ref_imp, + __make_tuple_indices_t>::value>, + _Tuple0, + _Tuples...> +{}; -template struct __tuple_cat; +template +struct __tuple_cat; template -struct __tuple_cat, __tuple_indices<_I0...>, - __tuple_indices<_J0...>> { +struct __tuple_cat, __tuple_indices<_I0...>, __tuple_indices<_J0...>> +{ template _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - typename __tuple_cat_return_ref &&, _Tuple0 &&>::type - operator()(tuple<_Types...> __t, _Tuple0 &&__t0) { - (void)__t; - return _CUDA_VSTD::forward_as_tuple( - _CUDA_VSTD::forward<_Types>(_CUDA_VSTD::get<_I0>(__t))..., - _CUDA_VSTD::get<_J0>(_CUDA_VSTD::forward<_Tuple0>(__t0))...); + typename __tuple_cat_return_ref&&, _Tuple0&&>::type + operator()(tuple<_Types...> __t, _Tuple0&& __t0) + { + (void) __t; + return _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Types>(_CUDA_VSTD::get<_I0>(__t))..., + _CUDA_VSTD::get<_J0>(_CUDA_VSTD::forward<_Tuple0>(__t0))...); } template _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - typename __tuple_cat_return_ref &&, _Tuple0 &&, - _Tuple1 &&, _Tuples &&...>::type - operator()(tuple<_Types...> __t, _Tuple0 &&__t0, _Tuple1 &&__t1, - _Tuples &&...__tpls) { - (void)__t; + typename __tuple_cat_return_ref&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type + operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) + { + (void) __t; typedef _LIBCUDACXX_NODEBUG_TYPE __libcpp_remove_reference_t<_Tuple0> _T0; typedef _LIBCUDACXX_NODEBUG_TYPE __libcpp_remove_reference_t<_Tuple1> _T1; - return __tuple_cat< - tuple<_Types..., typename __apply_cv< - _Tuple0, __tuple_element_t<_J0, _T0>>::type &&...>, - __make_tuple_indices_t::value>, - __make_tuple_indices_t::value>>()( - _CUDA_VSTD::forward_as_tuple( - _CUDA_VSTD::forward<_Types>(_CUDA_VSTD::get<_I0>(__t))..., - _CUDA_VSTD::get<_J0>(_CUDA_VSTD::forward<_Tuple0>(__t0))...), - _CUDA_VSTD::forward<_Tuple1>(__t1), - _CUDA_VSTD::forward<_Tuples>(__tpls)...); + return __tuple_cat>::type&&...>, + __make_tuple_indices_t::value>, + __make_tuple_indices_t::value>>()( + _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Types>(_CUDA_VSTD::get<_I0>(__t))..., + _CUDA_VSTD::get<_J0>(_CUDA_VSTD::forward<_Tuple0>(__t0))...), + _CUDA_VSTD::forward<_Tuple1>(__t1), + _CUDA_VSTD::forward<_Tuples>(__tpls)...); } }; template -inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 - typename __tuple_cat_return<_Tuple0, _Tuples...>::type - tuple_cat(_Tuple0 &&__t0, _Tuples &&...__tpls) { +inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX14 typename __tuple_cat_return<_Tuple0, _Tuples...>::type +tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) +{ typedef _LIBCUDACXX_NODEBUG_TYPE __libcpp_remove_reference_t<_Tuple0> _T0; - return __tuple_cat, __tuple_indices<>, - __make_tuple_indices_t::value>>()( - tuple<>(), _CUDA_VSTD::forward<_Tuple0>(__t0), - _CUDA_VSTD::forward<_Tuples>(__tpls)...); + return __tuple_cat, __tuple_indices<>, __make_tuple_indices_t::value>>()( + tuple<>(), _CUDA_VSTD::forward<_Tuple0>(__t0), _CUDA_VSTD::forward<_Tuples>(__tpls)...); } template -struct _LIBCUDACXX_TEMPLATE_VIS uses_allocator, _Alloc> - : true_type {}; +struct _LIBCUDACXX_TEMPLATE_VIS uses_allocator, _Alloc> : true_type +{}; template template @@ -1346,41 +1305,38 @@ inline _LIBCUDACXX_INLINE_VISIBILITY _CCCL_CONSTEXPR_CXX20 __pair_base<_T1, _T2, {} #if _CCCL_STD_VER > 2014 -#define _LIBCUDACXX_NOEXCEPT_RETURN(...) \ - noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } +# define _LIBCUDACXX_NOEXCEPT_RETURN(...) \ + noexcept(noexcept(__VA_ARGS__)) \ + { \ + return __VA_ARGS__; \ + } template inline _LIBCUDACXX_INLINE_VISIBILITY constexpr decltype(auto) -__apply_tuple_impl(_Fn &&__f, _Tuple &&__t, __tuple_indices<_Id...>) - _LIBCUDACXX_NOEXCEPT_RETURN(_CUDA_VSTD::__invoke( - _CUDA_VSTD::forward<_Fn>(__f), - _CUDA_VSTD::get<_Id>(_CUDA_VSTD::forward<_Tuple>(__t))...)) - - template - inline _LIBCUDACXX_INLINE_VISIBILITY - constexpr decltype(auto) apply(_Fn &&__f, _Tuple &&__t) - _LIBCUDACXX_NOEXCEPT_RETURN(_CUDA_VSTD::__apply_tuple_impl( - _CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Tuple>(__t), - __make_tuple_indices_t>>{})) - - template - inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp - __make_from_tuple_impl(_Tuple &&__t, __tuple_indices<_Idx...>) - _LIBCUDACXX_NOEXCEPT_RETURN( - _Tp(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::forward<_Tuple>(__t))...)) - - template - inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp - make_from_tuple(_Tuple &&__t) - _LIBCUDACXX_NOEXCEPT_RETURN(_CUDA_VSTD::__make_from_tuple_impl<_Tp>( - _CUDA_VSTD::forward<_Tuple>(__t), - __make_tuple_indices_t>>{})) - -#undef _LIBCUDACXX_NOEXCEPT_RETURN +__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, __tuple_indices<_Id...>) _LIBCUDACXX_NOEXCEPT_RETURN( + _CUDA_VSTD::__invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::get<_Id>(_CUDA_VSTD::forward<_Tuple>(__t))...)) + + template + inline _LIBCUDACXX_INLINE_VISIBILITY constexpr decltype(auto) apply(_Fn&& __f, _Tuple&& __t) + _LIBCUDACXX_NOEXCEPT_RETURN(_CUDA_VSTD::__apply_tuple_impl( + _CUDA_VSTD::forward<_Fn>(__f), + _CUDA_VSTD::forward<_Tuple>(__t), + __make_tuple_indices_t>>{})) + + template + inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) + _LIBCUDACXX_NOEXCEPT_RETURN(_Tp(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::forward<_Tuple>(__t))...)) + + template + inline _LIBCUDACXX_INLINE_VISIBILITY constexpr _Tp + make_from_tuple(_Tuple&& __t) _LIBCUDACXX_NOEXCEPT_RETURN(_CUDA_VSTD::__make_from_tuple_impl<_Tp>( + _CUDA_VSTD::forward<_Tuple>(__t), __make_tuple_indices_t>>{})) + +# undef _LIBCUDACXX_NOEXCEPT_RETURN #endif // _CCCL_STD_VER > 2014 - _LIBCUDACXX_END_NAMESPACE_STD + _LIBCUDACXX_END_NAMESPACE_STD #include //__cuda_std__ diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/type_traits b/libcudacxx/include/cuda/std/detail/libcxx/include/type_traits index fbdb588642d..e7f6eef7219 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/type_traits +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/type_traits @@ -425,10 +425,9 @@ namespace std #endif // no system header #include -#include // all public C++ headers provide the assertion handler -#include #include #include +#include #include #include #include @@ -505,14 +504,14 @@ namespace std #include #include #include -#include #include +#include #include #include #include #include -#include #include +#include #include #include #include @@ -527,14 +526,14 @@ namespace std #include #include #include -#include #include +#include #include #include #include #include -#include #include +#include #include #include #include @@ -543,10 +542,10 @@ namespace std #include #include #include -#include #include -#include +#include #include +#include #include #include #include @@ -561,21 +560,26 @@ namespace std #include #include #include -#include #include +#include +#include // all public C++ headers provide the assertion handler #include _LIBCUDACXX_BEGIN_NAMESPACE_STD -template class _LIBCUDACXX_TEMPLATE_VIS reference_wrapper; -template struct _LIBCUDACXX_TEMPLATE_VIS hash; +template +class _LIBCUDACXX_TEMPLATE_VIS reference_wrapper; +template +struct _LIBCUDACXX_TEMPLATE_VIS hash; -template struct _MetaBase; +template +struct _MetaBase; template <> -struct _MetaBase { +struct _MetaBase +{ template using _SelectImpl _LIBCUDACXX_NODEBUG_TYPE = _Tp; - template