Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more efficient enable_if_t implementation #3071

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion libcudacxx/include/cuda/std/__type_traits/enable_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
// SPDX-FileCopyrightText: Copyright (c) 2023-24 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -31,9 +31,30 @@ struct _CCCL_TYPE_VISIBILITY_DEFAULT enable_if<true, _Tp>
typedef _Tp type;
};

#if _CCCL_COMPILER(NVHPC) || _CCCL_COMPILER(ICC) || _CCCL_COMPILER(GCC, <, 8)

template <bool _Bp, class _Tp = void>
using enable_if_t _CCCL_NODEBUG_ALIAS = typename enable_if<_Bp, _Tp>::type;

#else // ^^^ standard implementation ^^^ / vvv optimized implementation

// Optimized enable_if_t implementation that does not instantiate a type every time
template <bool>
struct __enable_if_t_impl
{};

template <>
struct __enable_if_t_impl<true>
{
template <class _Tp>
using type = _Tp;
};

template <bool _Bp, class _Tp = void>
using enable_if_t _CCCL_NODEBUG_ALIAS = typename __enable_if_t_impl<_Bp>::template type<_Tp>;

#endif // !_CCCL_COMPILER(NVHPC) && !_CCCL_COMPILER(ICC) && !_CCCL_COMPILER(GCC, <, 8)

_LIBCUDACXX_END_NAMESPACE_STD

#endif // _LIBCUDACXX___TYPE_TRAITS_ENABLE_IF_H
Loading