Skip to content

Commit

Permalink
Enable std::variant for libcu++ (#1076)
Browse files Browse the repository at this point in the history
* Enable std::variant for libcu++
---------

Co-authored-by: Michał Dominiak <[email protected]>
  • Loading branch information
miscco and griwes committed Dec 12, 2023
1 parent 6540f9f commit 988800d
Show file tree
Hide file tree
Showing 120 changed files with 11,101 additions and 1,348 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ AttributeMacros: [
'_ALIGNAS',
'_LIBCUDACXX_ALIGNOF',
'_LIBCUDACXX_ALWAYS_INLINE',
'_LIBCUDACXX_AVAILABILITY_THROW_BAD_VARIANT_ACCESS',
'_LIBCUDACXX_CONSTEXPR_AFTER_CXX11',
'_LIBCUDACXX_CONSTEXPR_AFTER_CXX14',
'_LIBCUDACXX_CONSTEXPR_AFTER_CXX20',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ set(files
__utility/swap.h
__utility/to_underlying.h
__utility/unreachable.h
__variant/monostate.h
__verbose_abort
algorithm
any
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// -*- 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___VARIANT_MONOSTATE_H
#define _LIBCUDACXX___VARIANT_MONOSTATE_H

#ifndef __cuda_std__
#include <__config>
#endif // __cuda_std__

#ifndef _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR
#include "../__compare/ordering.h"
#endif // _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR
#include "../__functional/hash.h"

#include "../cstddef"

#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

#if _LIBCUDACXX_STD_VER >= 11

struct _LIBCUDACXX_TEMPLATE_VIS monostate {};

_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator==(monostate, monostate) noexcept { return true; }

#if _LIBCUDACXX_STD_VER < 20

_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator!=(monostate, monostate) noexcept { return false; }

#endif // _LIBCUDACXX_STD_VER < 20

#if _LIBCUDACXX_STD_VER >= 20 && !defined(_LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR)

_LIBCUDACXX_INLINE_VISIBILITY constexpr strong_ordering operator<=>(monostate, monostate) noexcept {
return strong_ordering::equal;
}

#else // _LIBCUDACXX_STD_VER >= 20

_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<(monostate, monostate) noexcept { return false; }

_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>(monostate, monostate) noexcept { return false; }

_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator<=(monostate, monostate) noexcept { return true; }

_LIBCUDACXX_INLINE_VISIBILITY constexpr bool operator>=(monostate, monostate) noexcept { return true; }

# endif // _LIBCUDACXX_STD_VER >= 20

#ifndef __cuda_std__
template <>
struct _LIBCUDACXX_TEMPLATE_VIS hash<monostate> {
using argument_type = monostate;
using result_type = size_t;

inline _LIBCUDACXX_INLINE_VISIBILITY result_type operator()(const argument_type&) const noexcept {
return 66740831; // return a fundamentally attractive random value.
}
};
#endif // __cuda_std__

#endif // _LIBCUDACXX_STD_VER >= 11

_LIBCUDACXX_END_NAMESPACE_STD

#endif // _LIBCUDACXX___VARIANT_MONOSTATE_H
Loading

0 comments on commit 988800d

Please sign in to comment.