diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-04-05 01:46:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-05 01:46:13 -0400 |
| commit | 0cd31fc7ff157551cfbba5da35cd79f118d2a2e3 (patch) | |
| tree | a308488f5d85184c8ec402fb3f55f1cf2704443e /lib/libcxx/libc/src/__support/CPP | |
| parent | 8acedfd5baabab705946ad097746f9183ef62420 (diff) | |
| parent | cefe65c1b8abe65a22d4b68410db1be264fdeda0 (diff) | |
| download | zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.tar.gz zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.zip | |
Merge pull request #22780 from ziglang/llvm20
LLVM 20
Diffstat (limited to 'lib/libcxx/libc/src/__support/CPP')
71 files changed, 3135 insertions, 0 deletions
diff --git a/lib/libcxx/libc/src/__support/CPP/array.h b/lib/libcxx/libc/src/__support/CPP/array.h new file mode 100644 index 0000000000..db0a986b71 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/array.h @@ -0,0 +1,80 @@ +//===-- A self contained equivalent of std::array ---------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_ARRAY_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_ARRAY_H + +#include "src/__support/CPP/iterator.h" // reverse_iterator +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" +#include <stddef.h> // For size_t. + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +template <class T, size_t N> struct array { + static_assert(N != 0, + "Cannot create a LIBC_NAMESPACE::cpp::array of size 0."); + + T Data[N]; + using value_type = T; + using iterator = T *; + using const_iterator = const T *; + using reverse_iterator = cpp::reverse_iterator<iterator>; + using const_reverse_iterator = cpp::reverse_iterator<const_iterator>; + + LIBC_INLINE constexpr T *data() { return Data; } + LIBC_INLINE constexpr const T *data() const { return Data; } + + LIBC_INLINE constexpr T &front() { return Data[0]; } + LIBC_INLINE constexpr const T &front() const { return Data[0]; } + + LIBC_INLINE constexpr T &back() { return Data[N - 1]; } + LIBC_INLINE constexpr const T &back() const { return Data[N - 1]; } + + LIBC_INLINE constexpr T &operator[](size_t Index) { return Data[Index]; } + + LIBC_INLINE constexpr const T &operator[](size_t Index) const { + return Data[Index]; + } + + LIBC_INLINE constexpr size_t size() const { return N; } + + LIBC_INLINE constexpr bool empty() const { return N == 0; } + + LIBC_INLINE constexpr iterator begin() { return Data; } + LIBC_INLINE constexpr const_iterator begin() const { return Data; } + LIBC_INLINE constexpr const_iterator cbegin() const { return begin(); } + + LIBC_INLINE constexpr iterator end() { return Data + N; } + LIBC_INLINE constexpr const_iterator end() const { return Data + N; } + LIBC_INLINE constexpr const_iterator cend() const { return end(); } + + LIBC_INLINE constexpr reverse_iterator rbegin() { + return reverse_iterator{end()}; + } + LIBC_INLINE constexpr const_reverse_iterator rbegin() const { + return const_reverse_iterator{end()}; + } + LIBC_INLINE constexpr const_reverse_iterator crbegin() const { + return rbegin(); + } + + LIBC_INLINE constexpr reverse_iterator rend() { + return reverse_iterator{begin()}; + } + LIBC_INLINE constexpr const_reverse_iterator rend() const { + return const_reverse_iterator{begin()}; + } + LIBC_INLINE constexpr const_reverse_iterator crend() const { return rend(); } +}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_ARRAY_H diff --git a/lib/libcxx/libc/src/__support/CPP/bit.h b/lib/libcxx/libc/src/__support/CPP/bit.h new file mode 100644 index 0000000000..adcd047274 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/bit.h @@ -0,0 +1,298 @@ +//===-- Implementation of the C++20 bit header -----------------*- 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 +// +//===----------------------------------------------------------------------===// +// This is inspired by LLVM ADT/bit.h header. +// Some functions are missing, we can add them as needed (popcount, byteswap). + +#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H + +#include "src/__support/CPP/limits.h" // numeric_limits +#include "src/__support/CPP/type_traits.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" +#include "src/__support/macros/sanitizer.h" + +#include <stdint.h> + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +#if __has_builtin(__builtin_memcpy_inline) +#define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE +#endif + +// This implementation of bit_cast requires trivially-constructible To, to avoid +// UB in the implementation. +template <typename To, typename From> +LIBC_INLINE constexpr cpp::enable_if_t< + (sizeof(To) == sizeof(From)) && + cpp::is_trivially_constructible<To>::value && + cpp::is_trivially_copyable<To>::value && + cpp::is_trivially_copyable<From>::value, + To> +bit_cast(const From &from) { + MSAN_UNPOISON(&from, sizeof(From)); +#if __has_builtin(__builtin_bit_cast) + return __builtin_bit_cast(To, from); +#else + To to; + char *dst = reinterpret_cast<char *>(&to); + const char *src = reinterpret_cast<const char *>(&from); +#if __has_builtin(__builtin_memcpy_inline) + __builtin_memcpy_inline(dst, src, sizeof(To)); +#else + for (unsigned i = 0; i < sizeof(To); ++i) + dst[i] = src[i]; +#endif // __has_builtin(__builtin_memcpy_inline) + return to; +#endif // __has_builtin(__builtin_bit_cast) +} + +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, + bool> +has_single_bit(T value) { + return (value != 0) && ((value & (value - 1)) == 0); +} + +// A temporary macro to add template function specialization when compiler +// builtin is available. +#define ADD_SPECIALIZATION(NAME, TYPE, BUILTIN) \ + template <> [[nodiscard]] LIBC_INLINE constexpr int NAME<TYPE>(TYPE value) { \ + static_assert(cpp::is_unsigned_v<TYPE>); \ + return value == 0 ? cpp::numeric_limits<TYPE>::digits : BUILTIN(value); \ + } + +/// Count number of 0's from the least significant bit to the most +/// stopping at the first 1. +/// +/// Only unsigned integral types are allowed. +/// +/// Returns cpp::numeric_limits<T>::digits on an input of 0. +// clang-19+, gcc-14+ +#if __has_builtin(__builtin_ctzg) +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countr_zero(T value) { + return __builtin_ctzg(value, cpp::numeric_limits<T>::digits); +} +#else +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countr_zero(T value) { + if (!value) + return cpp::numeric_limits<T>::digits; + if (value & 0x1) + return 0; + // Bisection method. + unsigned zero_bits = 0; + unsigned shift = cpp::numeric_limits<T>::digits >> 1; + T mask = cpp::numeric_limits<T>::max() >> shift; + while (shift) { + if ((value & mask) == 0) { + value >>= shift; + zero_bits |= shift; + } + shift >>= 1; + mask >>= shift; + } + return zero_bits; +} +#if __has_builtin(__builtin_ctzs) +ADD_SPECIALIZATION(countr_zero, unsigned short, __builtin_ctzs) +#endif +ADD_SPECIALIZATION(countr_zero, unsigned int, __builtin_ctz) +ADD_SPECIALIZATION(countr_zero, unsigned long, __builtin_ctzl) +ADD_SPECIALIZATION(countr_zero, unsigned long long, __builtin_ctzll) +#endif // __has_builtin(__builtin_ctzg) + +/// Count number of 0's from the most significant bit to the least +/// stopping at the first 1. +/// +/// Only unsigned integral types are allowed. +/// +/// Returns cpp::numeric_limits<T>::digits on an input of 0. +// clang-19+, gcc-14+ +#if __has_builtin(__builtin_clzg) +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countl_zero(T value) { + return __builtin_clzg(value, cpp::numeric_limits<T>::digits); +} +#else +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countl_zero(T value) { + if (!value) + return cpp::numeric_limits<T>::digits; + // Bisection method. + unsigned zero_bits = 0; + for (unsigned shift = cpp::numeric_limits<T>::digits >> 1; shift; + shift >>= 1) { + T tmp = value >> shift; + if (tmp) + value = tmp; + else + zero_bits |= shift; + } + return zero_bits; +} +#if __has_builtin(__builtin_clzs) +ADD_SPECIALIZATION(countl_zero, unsigned short, __builtin_clzs) +#endif +ADD_SPECIALIZATION(countl_zero, unsigned int, __builtin_clz) +ADD_SPECIALIZATION(countl_zero, unsigned long, __builtin_clzl) +ADD_SPECIALIZATION(countl_zero, unsigned long long, __builtin_clzll) +#endif // __has_builtin(__builtin_clzg) + +#undef ADD_SPECIALIZATION + +/// Count the number of ones from the most significant bit to the first +/// zero bit. +/// +/// Ex. countl_one(0xFF0FFF00) == 8. +/// Only unsigned integral types are allowed. +/// +/// Returns cpp::numeric_limits<T>::digits on an input of all ones. +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countl_one(T value) { + return cpp::countl_zero<T>(~value); +} + +/// Count the number of ones from the least significant bit to the first +/// zero bit. +/// +/// Ex. countr_one(0x00FF00FF) == 8. +/// Only unsigned integral types are allowed. +/// +/// Returns cpp::numeric_limits<T>::digits on an input of all ones. +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +countr_one(T value) { + return cpp::countr_zero<T>(~value); +} + +/// Returns the number of bits needed to represent value if value is nonzero. +/// Returns 0 otherwise. +/// +/// Ex. bit_width(5) == 3. +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +bit_width(T value) { + return cpp::numeric_limits<T>::digits - cpp::countl_zero(value); +} + +/// Returns the largest integral power of two no greater than value if value is +/// nonzero. Returns 0 otherwise. +/// +/// Ex. bit_floor(5) == 4. +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> +bit_floor(T value) { + if (!value) + return 0; + return static_cast<T>(T(1) << (cpp::bit_width(value) - 1)); +} + +/// Returns the smallest integral power of two no smaller than value if value is +/// nonzero. Returns 1 otherwise. +/// +/// Ex. bit_ceil(5) == 8. +/// +/// The return value is undefined if the input is larger than the largest power +/// of two representable in T. +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> +bit_ceil(T value) { + if (value < 2) + return 1; + return static_cast<T>(T(1) << cpp::bit_width(value - 1U)); +} + +// Rotate algorithms make use of "Safe, Efficient, and Portable Rotate in C/C++" +// from https://blog.regehr.org/archives/1063. + +// Forward-declare rotr so that rotl can use it. +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> +rotr(T value, int rotate); + +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> +rotl(T value, int rotate) { + constexpr unsigned N = cpp::numeric_limits<T>::digits; + rotate = rotate % N; + if (!rotate) + return value; + if (rotate < 0) + return cpp::rotr<T>(value, -rotate); + return (value << rotate) | (value >> (N - rotate)); +} + +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> +rotr(T value, int rotate) { + constexpr unsigned N = cpp::numeric_limits<T>::digits; + rotate = rotate % N; + if (!rotate) + return value; + if (rotate < 0) + return cpp::rotl<T>(value, -rotate); + return (value >> rotate) | (value << (N - rotate)); +} + +// TODO: Do we need this function at all? How is it different from +// 'static_cast'? +template <class To, class From> +LIBC_INLINE constexpr To bit_or_static_cast(const From &from) { + if constexpr (sizeof(To) == sizeof(From)) { + return bit_cast<To>(from); + } else { + return static_cast<To>(from); + } +} + +/// Count number of 1's aka population count or Hamming weight. +/// +/// Only unsigned integral types are allowed. +// clang-19+, gcc-14+ +#if __has_builtin(__builtin_popcountg) +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +popcount(T value) { + return __builtin_popcountg(value); +} +#else // !__has_builtin(__builtin_popcountg) +template <typename T> +[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, int> +popcount(T value) { + int count = 0; + while (value) { + value &= value - 1; + ++count; + } + return count; +} +#define ADD_SPECIALIZATION(TYPE, BUILTIN) \ + template <> \ + [[nodiscard]] LIBC_INLINE constexpr int popcount<TYPE>(TYPE value) { \ + return BUILTIN(value); \ + } +ADD_SPECIALIZATION(unsigned char, __builtin_popcount) +ADD_SPECIALIZATION(unsigned short, __builtin_popcount) +ADD_SPECIALIZATION(unsigned, __builtin_popcount) +ADD_SPECIALIZATION(unsigned long, __builtin_popcountl) +ADD_SPECIALIZATION(unsigned long long, __builtin_popcountll) +#endif // __builtin_popcountg +#undef ADD_SPECIALIZATION + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H diff --git a/lib/libcxx/libc/src/__support/CPP/iterator.h b/lib/libcxx/libc/src/__support/CPP/iterator.h new file mode 100644 index 0000000000..168a269731 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/iterator.h @@ -0,0 +1,99 @@ +//===-- Standalone implementation of iterator -------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_ITERATOR_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_ITERATOR_H + +#include "src/__support/CPP/type_traits/enable_if.h" +#include "src/__support/CPP/type_traits/is_convertible.h" +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +template <typename T> struct iterator_traits; +template <typename T> struct iterator_traits<T *> { + using reference = T &; + using value_type = T; +}; + +template <typename Iter> class reverse_iterator { + Iter current; + +public: + using reference = typename iterator_traits<Iter>::reference; + using value_type = typename iterator_traits<Iter>::value_type; + using iterator_type = Iter; + + LIBC_INLINE reverse_iterator() : current() {} + LIBC_INLINE constexpr explicit reverse_iterator(Iter it) : current(it) {} + + template <typename Other, + cpp::enable_if_t<!cpp::is_same_v<Iter, Other> && + cpp::is_convertible_v<const Other &, Iter>, + int> = 0> + LIBC_INLINE constexpr explicit reverse_iterator(const Other &it) + : current(it) {} + + LIBC_INLINE friend constexpr bool operator==(const reverse_iterator &lhs, + const reverse_iterator &rhs) { + return lhs.base() == rhs.base(); + } + + LIBC_INLINE friend constexpr bool operator!=(const reverse_iterator &lhs, + const reverse_iterator &rhs) { + return lhs.base() != rhs.base(); + } + + LIBC_INLINE friend constexpr bool operator<(const reverse_iterator &lhs, + const reverse_iterator &rhs) { + return lhs.base() > rhs.base(); + } + + LIBC_INLINE friend constexpr bool operator<=(const reverse_iterator &lhs, + const reverse_iterator &rhs) { + return lhs.base() >= rhs.base(); + } + + LIBC_INLINE friend constexpr bool operator>(const reverse_iterator &lhs, + const reverse_iterator &rhs) { + return lhs.base() < rhs.base(); + } + + LIBC_INLINE friend constexpr bool operator>=(const reverse_iterator &lhs, + const reverse_iterator &rhs) { + return lhs.base() <= rhs.base(); + } + + LIBC_INLINE constexpr iterator_type base() const { return current; } + + LIBC_INLINE constexpr reference operator*() const { + Iter tmp = current; + return *--tmp; + } + LIBC_INLINE constexpr reverse_iterator operator--() { + ++current; + return *this; + } + LIBC_INLINE constexpr reverse_iterator &operator++() { + --current; + return *this; + } + LIBC_INLINE constexpr reverse_iterator operator++(int) { + reverse_iterator tmp(*this); + --current; + return tmp; + } +}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_ITERATOR_H diff --git a/lib/libcxx/libc/src/__support/CPP/limits.h b/lib/libcxx/libc/src/__support/CPP/limits.h new file mode 100644 index 0000000000..cf4beb9cc8 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/limits.h @@ -0,0 +1,92 @@ +//===-- A self contained equivalent of std::limits --------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H + +#include "hdr/limits_macros.h" // CHAR_BIT +#include "src/__support/CPP/type_traits/is_integral.h" +#include "src/__support/CPP/type_traits/is_signed.h" +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +namespace internal { + +template <typename T, T min_value, T max_value> struct integer_impl { + static_assert(cpp::is_integral_v<T>); + LIBC_INLINE static constexpr T max() { return max_value; } + LIBC_INLINE static constexpr T min() { return min_value; } + LIBC_INLINE_VAR static constexpr int digits = + CHAR_BIT * sizeof(T) - cpp::is_signed_v<T>; +}; + +} // namespace internal + +template <class T> struct numeric_limits {}; + +// TODO: Add numeric_limits specializations as needed for new types. +template <> +struct numeric_limits<short> + : public internal::integer_impl<short, SHRT_MIN, SHRT_MAX> {}; + +template <> +struct numeric_limits<unsigned short> + : public internal::integer_impl<unsigned short, 0, USHRT_MAX> {}; + +template <> +struct numeric_limits<int> + : public internal::integer_impl<int, INT_MIN, INT_MAX> {}; + +template <> +struct numeric_limits<unsigned int> + : public internal::integer_impl<unsigned int, 0, UINT_MAX> {}; + +template <> +struct numeric_limits<long> + : public internal::integer_impl<long, LONG_MIN, LONG_MAX> {}; + +template <> +struct numeric_limits<unsigned long> + : public internal::integer_impl<unsigned long, 0, ULONG_MAX> {}; + +template <> +struct numeric_limits<long long> + : public internal::integer_impl<long long, LLONG_MIN, LLONG_MAX> {}; + +template <> +struct numeric_limits<unsigned long long> + : public internal::integer_impl<unsigned long long, 0, ULLONG_MAX> {}; + +template <> +struct numeric_limits<char> + : public internal::integer_impl<char, CHAR_MIN, CHAR_MAX> {}; + +template <> +struct numeric_limits<signed char> + : public internal::integer_impl<signed char, SCHAR_MIN, SCHAR_MAX> {}; + +template <> +struct numeric_limits<unsigned char> + : public internal::integer_impl<unsigned char, 0, UCHAR_MAX> {}; + +#ifdef LIBC_TYPES_HAS_INT128 +// On platform where UInt128 resolves to __uint128_t, this specialization +// provides the limits of UInt128. +template <> +struct numeric_limits<__uint128_t> + : public internal::integer_impl<__uint128_t, 0, ~__uint128_t(0)> {}; +#endif + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H diff --git a/lib/libcxx/libc/src/__support/CPP/optional.h b/lib/libcxx/libc/src/__support/CPP/optional.h new file mode 100644 index 0000000000..aed2269db1 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/optional.h @@ -0,0 +1,139 @@ +//===-- Standalone implementation of std::optional --------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_OPTIONAL_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_OPTIONAL_H + +#include "src/__support/CPP/type_traits.h" +#include "src/__support/CPP/utility.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// Trivial nullopt_t struct. +struct nullopt_t { + LIBC_INLINE constexpr explicit nullopt_t() = default; +}; + +// nullopt that can be used and returned. +LIBC_INLINE_VAR constexpr nullopt_t nullopt{}; + +// This is very simple implementation of the std::optional class. It makes +// several assumptions that the underlying type is trivially constructible, +// copyable, or movable. +template <typename T> class optional { + template <typename U, bool = !is_trivially_destructible<U>::value> + struct OptionalStorage { + union { + char empty; + U stored_value; + }; + + bool in_use = false; + + LIBC_INLINE ~OptionalStorage() { reset(); } + + LIBC_INLINE constexpr OptionalStorage() : empty() {} + + template <typename... Args> + LIBC_INLINE constexpr explicit OptionalStorage(in_place_t, Args &&...args) + : stored_value(forward<Args>(args)...) {} + + LIBC_INLINE constexpr void reset() { + if (in_use) + stored_value.~U(); + in_use = false; + } + }; + + // The only difference is that this type U doesn't have a nontrivial + // destructor. + template <typename U> struct OptionalStorage<U, false> { + union { + char empty; + U stored_value; + }; + + bool in_use = false; + + LIBC_INLINE constexpr OptionalStorage() : empty() {} + + template <typename... Args> + LIBC_INLINE constexpr explicit OptionalStorage(in_place_t, Args &&...args) + : stored_value(forward<Args>(args)...) {} + + LIBC_INLINE constexpr void reset() { in_use = false; } + }; + + OptionalStorage<T> storage; + +public: + LIBC_INLINE constexpr optional() = default; + LIBC_INLINE constexpr optional(nullopt_t) {} + + LIBC_INLINE constexpr optional(const T &t) : storage(in_place, t) { + storage.in_use = true; + } + LIBC_INLINE constexpr optional(const optional &) = default; + + LIBC_INLINE constexpr optional(T &&t) : storage(in_place, move(t)) { + storage.in_use = true; + } + LIBC_INLINE constexpr optional(optional &&O) = default; + + template <typename... ArgTypes> + LIBC_INLINE constexpr optional(in_place_t, ArgTypes &&...Args) + : storage(in_place, forward<ArgTypes>(Args)...) { + storage.in_use = true; + } + + LIBC_INLINE constexpr optional &operator=(T &&t) { + storage = move(t); + return *this; + } + LIBC_INLINE constexpr optional &operator=(optional &&) = default; + + LIBC_INLINE constexpr optional &operator=(const T &t) { + storage = t; + return *this; + } + LIBC_INLINE constexpr optional &operator=(const optional &) = default; + + LIBC_INLINE constexpr void reset() { storage.reset(); } + + LIBC_INLINE constexpr const T &value() const & { + return storage.stored_value; + } + + LIBC_INLINE constexpr T &value() & { return storage.stored_value; } + + LIBC_INLINE constexpr explicit operator bool() const { + return storage.in_use; + } + LIBC_INLINE constexpr bool has_value() const { return storage.in_use; } + LIBC_INLINE constexpr const T *operator->() const { + return &storage.stored_value; + } + LIBC_INLINE constexpr T *operator->() { return &storage.stored_value; } + LIBC_INLINE constexpr const T &operator*() const & { + return storage.stored_value; + } + LIBC_INLINE constexpr T &operator*() & { return storage.stored_value; } + + LIBC_INLINE constexpr T &&value() && { return move(storage.stored_value); } + LIBC_INLINE constexpr T &&operator*() && { + return move(storage.stored_value); + } +}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_OPTIONAL_H diff --git a/lib/libcxx/libc/src/__support/CPP/string_view.h b/lib/libcxx/libc/src/__support/CPP/string_view.h new file mode 100644 index 0000000000..745c62c35f --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/string_view.h @@ -0,0 +1,220 @@ +//===-- Standalone implementation std::string_view --------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H + +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +#include <stddef.h> + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// This is very simple alternate of the std::string_view class. There is no +// bounds check performed in any of the methods. The callers are expected to +// do the checks before invoking the methods. +// +// This class will be extended as needed in future. +class string_view { +private: + const char *Data; + size_t Len; + + LIBC_INLINE static size_t min(size_t A, size_t B) { return A <= B ? A : B; } + + LIBC_INLINE static int compareMemory(const char *Lhs, const char *Rhs, + size_t Length) { + for (size_t i = 0; i < Length; ++i) + if (int Diff = (int)Lhs[i] - (int)Rhs[i]) + return Diff; + return 0; + } + + LIBC_INLINE static constexpr size_t length(const char *Str) { + for (const char *End = Str;; ++End) + if (*End == '\0') + return End - Str; + } + + LIBC_INLINE bool equals(string_view Other) const { + return (Len == Other.Len && + compareMemory(Data, Other.Data, Other.Len) == 0); + } + +public: + using value_type = char; + using size_type = size_t; + using difference_type = ptrdiff_t; + using pointer = char *; + using const_pointer = const char *; + using reference = char &; + using const_reference = const char &; + using const_iterator = char *; + using iterator = const_iterator; + + // special value equal to the maximum value representable by the type + // size_type. + LIBC_INLINE_VAR static constexpr size_t npos = -1; + + LIBC_INLINE constexpr string_view() : Data(nullptr), Len(0) {} + + // Assumes Str is a null-terminated string. The length of the string does + // not include the terminating null character. + // Preconditions: [Str, Str + ​length(Str)) is a valid range. + LIBC_INLINE constexpr string_view(const char *Str) + : Data(Str), Len(length(Str)) {} + + // Preconditions: [Str, Str + N) is a valid range. + LIBC_INLINE constexpr string_view(const char *Str, size_t N) + : Data(Str), Len(N) {} + + LIBC_INLINE constexpr const char *data() const { return Data; } + + // Returns the size of the string_view. + LIBC_INLINE constexpr size_t size() const { return Len; } + + // Returns whether the string_view is empty. + LIBC_INLINE constexpr bool empty() const { return Len == 0; } + + // Returns an iterator to the first character of the view. + LIBC_INLINE const char *begin() const { return Data; } + + // Returns an iterator to the character following the last character of the + // view. + LIBC_INLINE const char *end() const { return Data + Len; } + + // Returns a const reference to the character at specified location pos. + // No bounds checking is performed: the behavior is undefined if pos >= + // size(). + LIBC_INLINE constexpr const char &operator[](size_t Index) const { + return Data[Index]; + } + + /// compare - Compare two strings; the result is -1, 0, or 1 if this string + /// is lexicographically less than, equal to, or greater than the \p Other. + LIBC_INLINE int compare(string_view Other) const { + // Check the prefix for a mismatch. + if (int Res = compareMemory(Data, Other.Data, min(Len, Other.Len))) + return Res < 0 ? -1 : 1; + // Otherwise the prefixes match, so we only need to check the lengths. + if (Len == Other.Len) + return 0; + return Len < Other.Len ? -1 : 1; + } + + LIBC_INLINE bool operator==(string_view Other) const { return equals(Other); } + LIBC_INLINE bool operator!=(string_view Other) const { + return !(*this == Other); + } + LIBC_INLINE bool operator<(string_view Other) const { + return compare(Other) == -1; + } + LIBC_INLINE bool operator<=(string_view Other) const { + return compare(Other) != 1; + } + LIBC_INLINE bool operator>(string_view Other) const { + return compare(Other) == 1; + } + LIBC_INLINE bool operator>=(string_view Other) const { + return compare(Other) != -1; + } + + // Moves the start of the view forward by n characters. + // The behavior is undefined if n > size(). + LIBC_INLINE void remove_prefix(size_t N) { + Len -= N; + Data += N; + } + + // Moves the end of the view back by n characters. + // The behavior is undefined if n > size(). + LIBC_INLINE void remove_suffix(size_t N) { Len -= N; } + + // Check if this string starts with the given Prefix. + LIBC_INLINE bool starts_with(string_view Prefix) const { + return Len >= Prefix.Len && + compareMemory(Data, Prefix.Data, Prefix.Len) == 0; + } + + // Check if this string starts with the given Prefix. + LIBC_INLINE bool starts_with(const char Prefix) const { + return !empty() && front() == Prefix; + } + + // Check if this string ends with the given Prefix. + LIBC_INLINE bool ends_with(const char Suffix) const { + return !empty() && back() == Suffix; + } + + // Check if this string ends with the given Suffix. + LIBC_INLINE bool ends_with(string_view Suffix) const { + return Len >= Suffix.Len && + compareMemory(end() - Suffix.Len, Suffix.Data, Suffix.Len) == 0; + } + + // Return a reference to the substring from [Start, Start + N). + // + // Start The index of the starting character in the substring; if the index is + // npos or greater than the length of the string then the empty substring will + // be returned. + // + // N The number of characters to included in the substring. If N exceeds the + // number of characters remaining in the string, the string suffix (starting + // with Start) will be returned. + LIBC_INLINE string_view substr(size_t Start, size_t N = npos) const { + Start = min(Start, Len); + return string_view(Data + Start, min(N, Len - Start)); + } + + // front - Get the first character in the string. + LIBC_INLINE char front() const { return Data[0]; } + + // back - Get the last character in the string. + LIBC_INLINE char back() const { return Data[Len - 1]; } + + // Finds the first occurence of c in this view, starting at position From. + LIBC_INLINE constexpr size_t find_first_of(const char c, + size_t From = 0) const { + for (size_t Pos = From; Pos < size(); ++Pos) + if ((*this)[Pos] == c) + return Pos; + return npos; + } + + // Finds the last occurence of c in this view, ending at position End. + LIBC_INLINE constexpr size_t find_last_of(const char c, + size_t End = npos) const { + End = End >= size() ? size() : End + 1; + for (; End > 0; --End) + if ((*this)[End - 1] == c) + return End - 1; + return npos; + } + + // Finds the first character not equal to c in this view, starting at position + // From. + LIBC_INLINE constexpr size_t find_first_not_of(const char c, + size_t From = 0) const { + for (size_t Pos = From; Pos < size(); ++Pos) + if ((*this)[Pos] != c) + return Pos; + return npos; + } + + // Check if this view contains the given character. + LIBC_INLINE constexpr bool contains(char c) const { + return find_first_of(c) != npos; + } +}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_STRING_VIEW_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits.h b/lib/libcxx/libc/src/__support/CPP/type_traits.h new file mode 100644 index 0000000000..d48ee23aea --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits.h @@ -0,0 +1,70 @@ +//===-- Self contained C++ type_traits --------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_H + +#include "src/__support/CPP/type_traits/add_lvalue_reference.h" +#include "src/__support/CPP/type_traits/add_pointer.h" +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/aligned_storage.h" +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/conditional.h" +#include "src/__support/CPP/type_traits/decay.h" +#include "src/__support/CPP/type_traits/enable_if.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/has_unique_object_representations.h" +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/CPP/type_traits/invoke.h" +#include "src/__support/CPP/type_traits/invoke_result.h" +#include "src/__support/CPP/type_traits/is_arithmetic.h" +#include "src/__support/CPP/type_traits/is_array.h" +#include "src/__support/CPP/type_traits/is_base_of.h" +#include "src/__support/CPP/type_traits/is_class.h" +#include "src/__support/CPP/type_traits/is_complex.h" +#include "src/__support/CPP/type_traits/is_const.h" +#include "src/__support/CPP/type_traits/is_constant_evaluated.h" +#include "src/__support/CPP/type_traits/is_convertible.h" +#include "src/__support/CPP/type_traits/is_copy_assignable.h" +#include "src/__support/CPP/type_traits/is_copy_constructible.h" +#include "src/__support/CPP/type_traits/is_destructible.h" +#include "src/__support/CPP/type_traits/is_enum.h" +#include "src/__support/CPP/type_traits/is_fixed_point.h" +#include "src/__support/CPP/type_traits/is_floating_point.h" +#include "src/__support/CPP/type_traits/is_function.h" +#include "src/__support/CPP/type_traits/is_integral.h" +#include "src/__support/CPP/type_traits/is_lvalue_reference.h" +#include "src/__support/CPP/type_traits/is_member_pointer.h" +#include "src/__support/CPP/type_traits/is_move_assignable.h" +#include "src/__support/CPP/type_traits/is_move_constructible.h" +#include "src/__support/CPP/type_traits/is_null_pointer.h" +#include "src/__support/CPP/type_traits/is_object.h" +#include "src/__support/CPP/type_traits/is_pointer.h" +#include "src/__support/CPP/type_traits/is_reference.h" +#include "src/__support/CPP/type_traits/is_rvalue_reference.h" +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/is_scalar.h" +#include "src/__support/CPP/type_traits/is_signed.h" +#include "src/__support/CPP/type_traits/is_trivially_constructible.h" +#include "src/__support/CPP/type_traits/is_trivially_copyable.h" +#include "src/__support/CPP/type_traits/is_trivially_destructible.h" +#include "src/__support/CPP/type_traits/is_union.h" +#include "src/__support/CPP/type_traits/is_unsigned.h" +#include "src/__support/CPP/type_traits/is_void.h" +#include "src/__support/CPP/type_traits/make_signed.h" +#include "src/__support/CPP/type_traits/make_unsigned.h" +#include "src/__support/CPP/type_traits/remove_all_extents.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/CPP/type_traits/remove_cvref.h" +#include "src/__support/CPP/type_traits/remove_extent.h" +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/CPP/type_traits/void_t.h" + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/add_lvalue_reference.h b/lib/libcxx/libc/src/__support/CPP/type_traits/add_lvalue_reference.h new file mode 100644 index 0000000000..6f5fc6b0a4 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/add_lvalue_reference.h @@ -0,0 +1,33 @@ +//===-- add_lvalue_reference type_traits ------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// add_lvalue_reference +namespace detail { +template <class T> // Note that `cv void&` is a substitution failure +auto try_add_lvalue_reference(int) -> cpp::type_identity<T &>; +template <class T> // Handle T = cv void case +auto try_add_lvalue_reference(...) -> cpp::type_identity<T>; +} // namespace detail +template <class T> +struct add_lvalue_reference : decltype(detail::try_add_lvalue_reference<T>(0)) { +}; +template <class T> +using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/add_pointer.h b/lib/libcxx/libc/src/__support/CPP/type_traits/add_pointer.h new file mode 100644 index 0000000000..2568a35653 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/add_pointer.h @@ -0,0 +1,30 @@ +//===-- add_pointer type_traits ---------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H + +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// add_pointer +namespace detail { +template <class T> +auto try_add_pointer(int) -> cpp::type_identity<cpp::remove_reference_t<T> *>; +template <class T> auto try_add_pointer(...) -> cpp::type_identity<T>; +} // namespace detail +template <class T> +struct add_pointer : decltype(detail::try_add_pointer<T>(0)) {}; +template <class T> using add_pointer_t = typename add_pointer<T>::type; +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/add_rvalue_reference.h b/lib/libcxx/libc/src/__support/CPP/type_traits/add_rvalue_reference.h new file mode 100644 index 0000000000..f51ebf46d7 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/add_rvalue_reference.h @@ -0,0 +1,32 @@ +//===-- add_rvalue_reference type_traits ------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// add_rvalue_reference +namespace detail { +template <class T> +auto try_add_rvalue_reference(int) -> cpp::type_identity<T &&>; +template <class T> auto try_add_rvalue_reference(...) -> cpp::type_identity<T>; +} // namespace detail +template <class T> +struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference<T>(0)) { +}; +template <class T> +using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/aligned_storage.h b/lib/libcxx/libc/src/__support/CPP/type_traits/aligned_storage.h new file mode 100644 index 0000000000..69ad4cc847 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/aligned_storage.h @@ -0,0 +1,30 @@ +//===-- aligned_storage type_traits --------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H + +#include "src/__support/macros/config.h" +#include <stddef.h> // size_t + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +template <size_t Len, size_t Align> struct aligned_storage { + struct type { + alignas(Align) unsigned char data[Len]; + }; +}; + +template <size_t Len, size_t Align> +using aligned_storage_t = typename aligned_storage<Len, Align>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALIGNED_STORAGE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/always_false.h b/lib/libcxx/libc/src/__support/CPP/type_traits/always_false.h new file mode 100644 index 0000000000..218eb9d577 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/always_false.h @@ -0,0 +1,32 @@ +//===-- convenient static_assert(false) helper ------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H + +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// This is technically not part of the standard but it come often enough that +// it's convenient to have around. +// +// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2593r0.html#valid-workaround +// +// This will be fixed in C++23 according to [CWG +// 2518](https://cplusplus.github.io/CWG/issues/2518.html). + +// Usage `static_assert(cpp::always_false<T>, "error message");` +template <typename...> LIBC_INLINE_VAR constexpr bool always_false = false; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ALWAYS_FALSE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/bool_constant.h b/lib/libcxx/libc/src/__support/CPP/type_traits/bool_constant.h new file mode 100644 index 0000000000..e61a81a84b --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/bool_constant.h @@ -0,0 +1,23 @@ +//===-- bool_constant type_traits -------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H + +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// bool_constant +template <bool V> using bool_constant = cpp::integral_constant<bool, V>; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/conditional.h b/lib/libcxx/libc/src/__support/CPP/type_traits/conditional.h new file mode 100644 index 0000000000..effcda02da --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/conditional.h @@ -0,0 +1,28 @@ +//===-- conditional type_traits ---------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// conditional +template <bool B, typename T, typename F> +struct conditional : type_identity<T> {}; +template <typename T, typename F> +struct conditional<false, T, F> : type_identity<F> {}; +template <bool B, typename T, typename F> +using conditional_t = typename conditional<B, T, F>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/decay.h b/lib/libcxx/libc/src/__support/CPP/type_traits/decay.h new file mode 100644 index 0000000000..c07e9e8557 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/decay.h @@ -0,0 +1,40 @@ +//===-- decay type_traits ---------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H + +#include "src/__support/macros/attributes.h" + +#include "src/__support/CPP/type_traits/add_pointer.h" +#include "src/__support/CPP/type_traits/conditional.h" +#include "src/__support/CPP/type_traits/is_array.h" +#include "src/__support/CPP/type_traits/is_function.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/CPP/type_traits/remove_extent.h" +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// decay +template <class T> class decay { + using U = cpp::remove_reference_t<T>; + +public: + using type = conditional_t< + cpp::is_array_v<U>, cpp::add_pointer_t<cpp::remove_extent_t<U>>, + cpp::conditional_t<cpp::is_function_v<U>, cpp::add_pointer_t<U>, + cpp::remove_cv_t<U>>>; +}; +template <class T> using decay_t = typename decay<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_DECAY_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/enable_if.h b/lib/libcxx/libc/src/__support/CPP/type_traits/enable_if.h new file mode 100644 index 0000000000..a2ce2037eb --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/enable_if.h @@ -0,0 +1,26 @@ +//===-- enable_if type_traits -----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// enable_if +template <bool B, typename T = void> struct enable_if; +template <typename T> struct enable_if<true, T> : type_identity<T> {}; +template <bool B, typename T = void> +using enable_if_t = typename enable_if<B, T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/false_type.h b/lib/libcxx/libc/src/__support/CPP/type_traits/false_type.h new file mode 100644 index 0000000000..65934b96ba --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/false_type.h @@ -0,0 +1,23 @@ +//===-- false_type type_traits ----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// false_type +using false_type = cpp::bool_constant<false>; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/has_unique_object_representations.h b/lib/libcxx/libc/src/__support/CPP/type_traits/has_unique_object_representations.h new file mode 100644 index 0000000000..639fb69d27 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/has_unique_object_representations.h @@ -0,0 +1,30 @@ +//===-- has_unique_object_representations type_traits ------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATIONS_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATIONS_H + +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/CPP/type_traits/remove_all_extents.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +template <class T> +struct has_unique_object_representations + : public integral_constant<bool, __has_unique_object_representations( + remove_all_extents_t<T>)> {}; + +template <class T> +LIBC_INLINE_VAR constexpr bool has_unique_object_representations_v = + has_unique_object_representations<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATIONS_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/integral_constant.h b/lib/libcxx/libc/src/__support/CPP/type_traits/integral_constant.h new file mode 100644 index 0000000000..931a9b98a6 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/integral_constant.h @@ -0,0 +1,26 @@ +//===-- integral_constant type_traits ---------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H + +#include "src/__support/macros/attributes.h" // LIBC_INLINE_VAR +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// integral_constant +template <typename T, T v> struct integral_constant { + using value_type = T; + LIBC_INLINE_VAR static constexpr T value = v; +}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/invoke.h b/lib/libcxx/libc/src/__support/CPP/type_traits/invoke.h new file mode 100644 index 0000000000..e4d9be74d1 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/invoke.h @@ -0,0 +1,67 @@ +//===-- invoke type_traits --------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_H + +#include "src/__support/CPP/type_traits/always_false.h" +#include "src/__support/CPP/type_traits/decay.h" +#include "src/__support/CPP/type_traits/enable_if.h" +#include "src/__support/CPP/type_traits/is_base_of.h" +#include "src/__support/CPP/type_traits/is_pointer.h" +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/utility/forward.h" +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +namespace detail { + +// Catch all function and functor types. +template <class FunctionPtrType> struct invoke_dispatcher { + template <class T, class... Args, + typename = cpp::enable_if_t< + cpp::is_same_v<cpp::decay_t<T>, FunctionPtrType>>> + LIBC_INLINE static decltype(auto) call(T &&fun, Args &&...args) { + return cpp::forward<T>(fun)(cpp::forward<Args>(args)...); + } +}; + +// Catch pointer to member function types. +template <class Class, class FunctionReturnType> +struct invoke_dispatcher<FunctionReturnType Class::*> { + using FunctionPtrType = FunctionReturnType Class::*; + + template <class T, class... Args, class DecayT = cpp::decay_t<T>> + LIBC_INLINE static decltype(auto) call(FunctionPtrType fun, T &&t1, + Args &&...args) { + if constexpr (cpp::is_base_of_v<Class, DecayT>) { + // T is a (possibly cv ref) type. + return (cpp::forward<T>(t1).*fun)(cpp::forward<Args>(args)...); + } else if constexpr (cpp::is_pointer_v<T>) { + // T is a pointer type. + return (*cpp::forward<T>(t1).*fun)(cpp::forward<Args>(args)...); + } else { + static_assert(cpp::always_false<T>); + } + } +}; + +} // namespace detail +template <class Function, class... Args> +decltype(auto) invoke(Function &&fun, Args &&...args) { + return detail::invoke_dispatcher<cpp::decay_t<Function>>::call( + cpp::forward<Function>(fun), cpp::forward<Args>(args)...); +} + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/invoke_result.h b/lib/libcxx/libc/src/__support/CPP/type_traits/invoke_result.h new file mode 100644 index 0000000000..71d848b77f --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/invoke_result.h @@ -0,0 +1,29 @@ +//===-- invoke_result type_traits -------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H + +#include "src/__support/CPP/type_traits/invoke.h" +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/CPP/utility/declval.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +template <class F, class... Args> +struct invoke_result : cpp::type_identity<decltype(cpp::invoke( + cpp::declval<F>(), cpp::declval<Args>()...))> {}; + +template <class F, class... Args> +using invoke_result_t = typename invoke_result<F, Args...>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_INVOKE_RESULT_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_arithmetic.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_arithmetic.h new file mode 100644 index 0000000000..33671b0def --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_arithmetic.h @@ -0,0 +1,30 @@ +//===-- is_arithmetic type_traits -------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_floating_point.h" +#include "src/__support/CPP/type_traits/is_integral.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_arithmetic +template <typename T> +struct is_arithmetic : cpp::bool_constant<(cpp::is_integral_v<T> || + cpp::is_floating_point_v<T>)> {}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_arithmetic_v = is_arithmetic<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_array.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_array.h new file mode 100644 index 0000000000..f0ab100fd5 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_array.h @@ -0,0 +1,31 @@ +//===-- is_array type_traits ------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +#include <stddef.h> // For size_t + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_array +template <class T> struct is_array : false_type {}; +template <class T> struct is_array<T[]> : true_type {}; +template <class T, size_t N> struct is_array<T[N]> : true_type {}; +template <class T> +LIBC_INLINE_VAR constexpr bool is_array_v = is_array<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_base_of.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_base_of.h new file mode 100644 index 0000000000..2efd1bf3f1 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_base_of.h @@ -0,0 +1,47 @@ +//===-- is_base_of type_traits ----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H + +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/is_class.h" +#include "src/__support/CPP/type_traits/remove_all_extents.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_base_of +namespace detail { +template <typename B> cpp::true_type __test_ptr_conv(const volatile B *); +template <typename> cpp::false_type __test_ptr_conv(const volatile void *); + +template <typename B, typename D> +auto is_base_of(int) -> decltype(__test_ptr_conv<B>(static_cast<D *>(nullptr))); + +template <typename, typename> +auto is_base_of(...) -> cpp::true_type; // private or ambiguous base + +} // namespace detail + +template <typename Base, typename Derived> +struct is_base_of + : cpp::bool_constant< + cpp::is_class_v<Base> && + cpp::is_class_v<Derived> &&decltype(detail::is_base_of<Base, Derived>( + 0))::value> {}; +template <typename Base, typename Derived> +LIBC_INLINE_VAR constexpr bool is_base_of_v = is_base_of<Base, Derived>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_class.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_class.h new file mode 100644 index 0000000000..fe12f7d276 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_class.h @@ -0,0 +1,32 @@ +//===-- is_class type_traits ------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/is_union.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_class +namespace detail { +template <class T> cpp::bool_constant<!cpp::is_union_v<T>> test(int T::*); +template <class> cpp::false_type test(...); +} // namespace detail +template <class T> struct is_class : decltype(detail::test<T>(nullptr)) {}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_class_v = is_class<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_complex.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_complex.h new file mode 100644 index 0000000000..23f05c08cc --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_complex.h @@ -0,0 +1,53 @@ +//===-- is_complex type_traits ----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COMPLEX_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COMPLEX_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" +// LIBC_TYPES_HAS_CFLOAT16 && LIBC_TYPES_HAS_CFLOAT128 +#include "src/__support/macros/properties/complex_types.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_complex +template <typename T> struct is_complex { +private: + template <typename Head, typename... Args> + LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() { + return (... || is_same_v<remove_cv_t<Head>, Args>); + } + +public: + LIBC_INLINE_VAR static constexpr bool value = + __is_unqualified_any_of<T, _Complex float, _Complex double, + _Complex long double +#ifdef LIBC_TYPES_HAS_CFLOAT16 + , + cfloat16 +#endif +#ifdef LIBC_TYPES_HAS_CFLOAT128 + , + cfloat128 +#endif + >(); +}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_complex_v = is_complex<T>::value; +template <typename T1, typename T2> +LIBC_INLINE_VAR constexpr bool is_complex_type_same() { + return is_same_v<remove_cv_t<T1>, T2>; +} + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COMPLEX_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_const.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_const.h new file mode 100644 index 0000000000..b8e60f79a6 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_const.h @@ -0,0 +1,28 @@ +//===-- is_const type_traits ------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_const +template <class T> struct is_const : cpp::false_type {}; +template <class T> struct is_const<const T> : cpp::true_type {}; +template <class T> +LIBC_INLINE_VAR constexpr bool is_const_v = is_const<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_constant_evaluated.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_constant_evaluated.h new file mode 100644 index 0000000000..0bb2d0806c --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_constant_evaluated.h @@ -0,0 +1,24 @@ +//===-- is_constant_evaluated type_traits -----------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H + +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +LIBC_INLINE constexpr bool is_constant_evaluated() { + return __builtin_is_constant_evaluated(); +} + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONSTANT_EVALUATED_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_convertible.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_convertible.h new file mode 100644 index 0000000000..a9f94cbb95 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_convertible.h @@ -0,0 +1,48 @@ +//===-- is_convertible type_traits ------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H + +#include "src/__support/CPP/type_traits/is_void.h" +#include "src/__support/CPP/utility/declval.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_convertible +namespace detail { +template <class T> +auto test_returnable(int) + -> decltype(void(static_cast<T (*)()>(nullptr)), cpp::true_type{}); +template <class> auto test_returnable(...) -> cpp::false_type; + +template <class From, class To> +auto test_implicitly_convertible(int) + -> decltype(void(cpp::declval<void (&)(To)>()(cpp::declval<From>())), + cpp::true_type{}); +template <class, class> +auto test_implicitly_convertible(...) -> cpp::false_type; +} // namespace detail + +template <class From, class To> +struct is_convertible + : cpp::bool_constant< + (decltype(detail::test_returnable<To>(0))::value && + decltype(detail::test_implicitly_convertible<From, To>(0))::value) || + (cpp::is_void_v<From> && cpp::is_void_v<To>)> {}; + +template <class From, class To> +LIBC_INLINE_VAR constexpr bool is_convertible_v = + is_convertible<From, To>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_assignable.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_assignable.h new file mode 100644 index 0000000000..9beb93d146 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_assignable.h @@ -0,0 +1,32 @@ +//===-- is_copy_assignable type_traits --------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_ASSIGNABLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_ASSIGNABLE_H + +#include "src/__support/CPP/type_traits/add_lvalue_reference.h" +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is copy assignable +template <class T> +struct is_copy_assignable + : public integral_constant< + bool, __is_assignable(cpp::add_lvalue_reference_t<T>, + cpp::add_lvalue_reference_t<const T>)> {}; + +template <class T> +LIBC_INLINE_VAR constexpr bool is_copy_assignable_v = + is_copy_assignable<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_ASSIGNABLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_constructible.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_constructible.h new file mode 100644 index 0000000000..d8eb9ad350 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_copy_constructible.h @@ -0,0 +1,31 @@ +//===-- is_copy_constructible type_traits -----------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H + +#include "src/__support/CPP/type_traits/add_lvalue_reference.h" +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is copy constructible +template <class T> +struct is_copy_constructible + : public integral_constant< + bool, __is_constructible(T, cpp::add_lvalue_reference_t<const T>)> {}; + +template <class T> +LIBC_INLINE_VAR constexpr bool is_copy_constructible_v = + is_copy_constructible<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_COPY_CONSTRUCTIBLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_destructible.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_destructible.h new file mode 100644 index 0000000000..830f22efaf --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_destructible.h @@ -0,0 +1,68 @@ +//===-- is_destructible type_traits -----------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/is_function.h" +#include "src/__support/CPP/type_traits/is_reference.h" +#include "src/__support/CPP/type_traits/remove_all_extents.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_destructible +#if __has_builtin(__is_destructible) +template <typename T> +struct is_destructible : bool_constant<__is_destructible(T)> {}; +#else +// if it's a reference, return true +// if it's a function, return false +// if it's void, return false +// if it's an array of unknown bound, return false +// Otherwise, return "declval<T&>().~T()" is well-formed +// where T is remove_all_extents<T>::type +template <typename> struct __is_destructible_apply : cpp::type_identity<int> {}; +template <typename T> struct __is_destructor_wellformed { + template <typename T1> + static cpp::true_type __test( + typename __is_destructible_apply<decltype(declval<T1 &>().~T1())>::type); + template <typename T1> static cpp::false_type __test(...); + static const bool value = decltype(__test<T>(12))::value; +}; +template <typename T, bool> struct __destructible_imp; +template <typename T> +struct __destructible_imp<T, false> + : public bool_constant< + __is_destructor_wellformed<cpp::remove_all_extents_t<T>>::value> {}; +template <typename T> +struct __destructible_imp<T, true> : public cpp::true_type {}; +template <typename T, bool> struct __destructible_false; +template <typename T> +struct __destructible_false<T, false> + : public __destructible_imp<T, is_reference<T>::value> {}; +template <typename T> +struct __destructible_false<T, true> : public cpp::false_type {}; +template <typename T> +struct is_destructible : public __destructible_false<T, is_function<T>::value> { +}; +template <typename T> struct is_destructible<T[]> : public false_type {}; +template <> struct is_destructible<void> : public false_type {}; +#endif +template <class T> +LIBC_INLINE_VAR constexpr bool is_destructible_v = is_destructible<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_enum.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_enum.h new file mode 100644 index 0000000000..623ae072af --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_enum.h @@ -0,0 +1,26 @@ +//===-- is_enum type_traits -------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_enum +template <typename T> struct is_enum : bool_constant<__is_enum(T)> {}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_enum_v = is_enum<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_fixed_point.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_fixed_point.h new file mode 100644 index 0000000000..9df2a7727c --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_fixed_point.h @@ -0,0 +1,49 @@ +//===-- is_fixed_point type_traits ------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" + +#include "include/llvm-libc-macros/stdfix-macros.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_fixed_point +#ifdef LIBC_COMPILER_HAS_FIXED_POINT +template <typename T> struct is_fixed_point { +private: + template <typename Head, typename... Args> + LIBC_INLINE static constexpr bool __is_unqualified_any_of() { + return (... || is_same_v<remove_cv_t<Head>, Args>); + } + +public: + LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of< + T, short fract, fract, long fract, unsigned short fract, unsigned fract, + unsigned long fract, short accum, accum, long accum, unsigned short accum, + unsigned accum, unsigned long accum, short sat fract, sat fract, + long sat fract, unsigned short sat fract, unsigned sat fract, + unsigned long sat fract, short sat accum, sat accum, long sat accum, + unsigned short sat accum, unsigned sat accum, unsigned long sat accum>(); +}; +#else +template <typename T> struct is_fixed_point : false_type {}; +#endif // LIBC_COMPILER_HAS_FIXED_POINT + +template <typename T> +LIBC_INLINE_VAR constexpr bool is_fixed_point_v = is_fixed_point<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_floating_point.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_floating_point.h new file mode 100644 index 0000000000..11ffbfabe6 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_floating_point.h @@ -0,0 +1,48 @@ +//===-- is_floating_point type_traits ---------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128 + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_floating_point +template <typename T> struct is_floating_point { +private: + template <typename Head, typename... Args> + LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() { + return (... || is_same_v<remove_cv_t<Head>, Args>); + } + +public: + LIBC_INLINE_VAR static constexpr bool value = + __is_unqualified_any_of<T, float, double, long double +#ifdef LIBC_TYPES_HAS_FLOAT16 + , + float16 +#endif +#ifdef LIBC_TYPES_HAS_FLOAT128 + , + float128 +#endif + >(); +}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_floating_point_v = + is_floating_point<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_function.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_function.h new file mode 100644 index 0000000000..f7717f0a4d --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_function.h @@ -0,0 +1,35 @@ +//===-- is_function type_traits ---------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_const.h" +#include "src/__support/CPP/type_traits/is_reference.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_function +#if __has_builtin(__is_function) +template <typename T> +struct is_function : integral_constant<bool, __is_function(T)> {}; +#else +template <typename T> +struct is_function + : public bool_constant<!(is_reference_v<T> || is_const_v<const T>)> {}; +#endif +template <class T> +LIBC_INLINE_VAR constexpr bool is_function_v = is_function<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_integral.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_integral.h new file mode 100644 index 0000000000..96ba09a07d --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_integral.h @@ -0,0 +1,43 @@ +//===-- is_integral type_traits ---------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_integral +template <typename T> struct is_integral { +private: + template <typename Head, typename... Args> + LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() { + return (... || is_same_v<remove_cv_t<Head>, Args>); + } + +public: + LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of< + T, +#ifdef LIBC_TYPES_HAS_INT128 + __int128_t, __uint128_t, +#endif + char, signed char, unsigned char, short, unsigned short, int, + unsigned int, long, unsigned long, long long, unsigned long long, bool>(); +}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_integral_v = is_integral<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_lvalue_reference.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_lvalue_reference.h new file mode 100644 index 0000000000..e0bfbebdaa --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_lvalue_reference.h @@ -0,0 +1,35 @@ +//===-- is_lvalue_reference type_traits -------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_lvalue_reference +#if __has_builtin(__is_lvalue_reference) +template <typename T> +struct is_lvalue_reference : bool_constant<__is_lvalue_reference(T)> {}; +#else +template <typename T> struct is_lvalue_reference : public false_type {}; +template <typename T> struct is_lvalue_reference<T &> : public true_type {}; +#endif +template <class T> +LIBC_INLINE_VAR constexpr bool is_lvalue_reference_v = + is_lvalue_reference<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_member_pointer.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_member_pointer.h new file mode 100644 index 0000000000..f445670039 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_member_pointer.h @@ -0,0 +1,33 @@ +//===-- is_member_pointer type_traits ---------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_member_pointer +template <class T> struct is_member_pointer_helper : cpp::false_type {}; +template <class T, class U> +struct is_member_pointer_helper<T U::*> : cpp::true_type {}; +template <class T> +struct is_member_pointer : is_member_pointer_helper<cpp::remove_cv_t<T>> {}; +template <class T> +LIBC_INLINE_VAR constexpr bool is_member_pointer_v = + is_member_pointer<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_move_assignable.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_move_assignable.h new file mode 100644 index 0000000000..a788bd9074 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_move_assignable.h @@ -0,0 +1,33 @@ +//===-- is_move_assignable type_traits --------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H + +#include "src/__support/CPP/type_traits/add_lvalue_reference.h" +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is move assignable +template <class T> +struct is_move_assignable + : public integral_constant<bool, __is_assignable( + cpp::add_lvalue_reference_t<T>, + cpp::add_rvalue_reference_t<T>)> {}; + +template <class T> +LIBC_INLINE_VAR constexpr bool is_move_assignable_v = + is_move_assignable<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_ASSIGNABLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_move_constructible.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_move_constructible.h new file mode 100644 index 0000000000..c898960546 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_move_constructible.h @@ -0,0 +1,31 @@ +//===-- is_move_constructible type_traits ------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H + +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is move constructible +template <class T> +struct is_move_constructible + : public integral_constant<bool, __is_constructible( + T, cpp::add_rvalue_reference_t<T>)> {}; + +template <class T> +LIBC_INLINE_VAR constexpr bool is_move_constructible_v = + is_move_constructible<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_MOVE_CONSTRUCTIBLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_null_pointer.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_null_pointer.h new file mode 100644 index 0000000000..acf341311b --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_null_pointer.h @@ -0,0 +1,29 @@ +//===-- is_null_pointer type_traits -----------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_null_pointer +using nullptr_t = decltype(nullptr); +template <class T> +struct is_null_pointer : cpp::is_same<cpp::nullptr_t, cpp::remove_cv_t<T>> {}; +template <class T> +LIBC_INLINE_VAR constexpr bool is_null_pointer_v = is_null_pointer<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_object.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_object.h new file mode 100644 index 0000000000..16799fb8f2 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_object.h @@ -0,0 +1,33 @@ +//===-- is_object type_traits -----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_OBJECT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_OBJECT_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_array.h" +#include "src/__support/CPP/type_traits/is_class.h" +#include "src/__support/CPP/type_traits/is_scalar.h" +#include "src/__support/CPP/type_traits/is_union.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_object +template <class T> +struct is_object + : cpp::bool_constant<cpp::is_scalar_v<T> || cpp::is_array_v<T> || + cpp::is_union_v<T> || cpp::is_class_v<T>> {}; +template <class T> +LIBC_INLINE_VAR constexpr bool is_object_v = is_object<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_OBJECT_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_pointer.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_pointer.h new file mode 100644 index 0000000000..606c8e9e8c --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_pointer.h @@ -0,0 +1,31 @@ +//===-- is_pointer type_traits ----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_pointer +template <typename T> struct is_pointer : cpp::false_type {}; +template <typename T> struct is_pointer<T *> : cpp::true_type {}; +template <typename T> struct is_pointer<T *const> : cpp::true_type {}; +template <typename T> struct is_pointer<T *volatile> : cpp::true_type {}; +template <typename T> struct is_pointer<T *const volatile> : cpp::true_type {}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_pointer_v = is_pointer<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_reference.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_reference.h new file mode 100644 index 0000000000..12da81778f --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_reference.h @@ -0,0 +1,34 @@ +//===-- is_reference type_traits --------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_reference +#if __has_builtin(__is_reference) +template <typename T> struct is_reference : bool_constant<__is_reference(T)> {}; +#else +template <typename T> struct is_reference : public false_type {}; +template <typename T> struct is_reference<T &> : public true_type {}; +template <typename T> struct is_reference<T &&> : public true_type {}; +#endif +template <class T> +LIBC_INLINE_VAR constexpr bool is_reference_v = is_reference<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_rvalue_reference.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_rvalue_reference.h new file mode 100644 index 0000000000..998b6353af --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_rvalue_reference.h @@ -0,0 +1,35 @@ +//===-- is_rvalue_reference type_traits -------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_rvalue_reference +#if __has_builtin(__is_rvalue_reference) +template <typename T> +struct is_rvalue_reference : bool_constant<__is_rvalue_reference(T)> {}; +#else +template <typename T> struct is_rvalue_reference : public false_type {}; +template <typename T> struct is_rvalue_reference<T &&> : public true_type {}; +#endif +template <class T> +LIBC_INLINE_VAR constexpr bool is_rvalue_reference_v = + is_rvalue_reference<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_same.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_same.h new file mode 100644 index 0000000000..306d16b86f --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_same.h @@ -0,0 +1,28 @@ +//===-- is_same type_traits -------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_same +template <typename T, typename U> struct is_same : cpp::false_type {}; +template <typename T> struct is_same<T, T> : cpp::true_type {}; +template <typename T, typename U> +LIBC_INLINE_VAR constexpr bool is_same_v = is_same<T, U>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_scalar.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_scalar.h new file mode 100644 index 0000000000..7f8a750cd7 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_scalar.h @@ -0,0 +1,35 @@ +//===-- is_scalar type_traits -----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_arithmetic.h" +#include "src/__support/CPP/type_traits/is_enum.h" +#include "src/__support/CPP/type_traits/is_member_pointer.h" +#include "src/__support/CPP/type_traits/is_null_pointer.h" +#include "src/__support/CPP/type_traits/is_pointer.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_scalar +template <class T> +struct is_scalar + : cpp::bool_constant<cpp::is_arithmetic_v<T> || cpp::is_enum_v<T> || + cpp::is_pointer_v<T> || cpp::is_member_pointer_v<T> || + cpp::is_null_pointer_v<T>> {}; +template <class T> +LIBC_INLINE_VAR constexpr bool is_scalar_v = is_scalar<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SCALAR_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_signed.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_signed.h new file mode 100644 index 0000000000..3f56fb38aa --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_signed.h @@ -0,0 +1,31 @@ +//===-- is_signed type_traits -----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_arithmetic.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_signed +template <typename T> +struct is_signed : bool_constant<(is_arithmetic_v<T> && (T(-1) < T(0)))> { + LIBC_INLINE constexpr operator bool() const { return is_signed::value; } + LIBC_INLINE constexpr bool operator()() const { return is_signed::value; } +}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_signed_v = is_signed<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_constructible.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_constructible.h new file mode 100644 index 0000000000..b801911038 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_constructible.h @@ -0,0 +1,25 @@ +//===-- is_trivially_constructible type_traits ------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H + +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_trivially_constructible +template <class T, class... Args> +struct is_trivially_constructible + : integral_constant<bool, __is_trivially_constructible(T, Args...)> {}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_copyable.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_copyable.h new file mode 100644 index 0000000000..a3e786fe1d --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_copyable.h @@ -0,0 +1,29 @@ +//===-- is_trivially_copyable type_traits -----------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H + +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_trivially_copyable +template <class T> +struct is_trivially_copyable + : public integral_constant<bool, __is_trivially_copyable(T)> {}; + +template <class T> +LIBC_INLINE_VAR constexpr bool is_trivially_copyable_v = + is_trivially_copyable<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_destructible.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_destructible.h new file mode 100644 index 0000000000..d727a0ec3a --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_trivially_destructible.h @@ -0,0 +1,37 @@ +//===-- is_trivially_destructible type_traits -------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_destructible.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_trivially_destructible +#if __has_builtin(__is_trivially_destructible) +template <typename T> +struct is_trivially_destructible + : public bool_constant<__is_trivially_destructible(T)> {}; +#else +template <typename T> +struct is_trivially_destructible + : public bool_constant<cpp::is_destructible_v<T> &&__has_trivial_destructor( + T)> {}; +#endif // __has_builtin(__is_trivially_destructible) +template <typename T> +LIBC_INLINE_VAR constexpr bool is_trivially_destructible_v = + is_trivially_destructible<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_union.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_union.h new file mode 100644 index 0000000000..00ca11a351 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_union.h @@ -0,0 +1,26 @@ +//===-- is_union type_traits ------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_union +template <class T> struct is_union : bool_constant<__is_union(T)> {}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_union_v = is_union<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_unsigned.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_unsigned.h new file mode 100644 index 0000000000..eed519b1c0 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_unsigned.h @@ -0,0 +1,31 @@ +//===-- is_unsigned type_traits ---------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_arithmetic.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_unsigned +template <typename T> +struct is_unsigned : bool_constant<(is_arithmetic_v<T> && (T(-1) > T(0)))> { + LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; } + LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; } +}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_unsigned_v = is_unsigned<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/is_void.h b/lib/libcxx/libc/src/__support/CPP/type_traits/is_void.h new file mode 100644 index 0000000000..30459dcf91 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/is_void.h @@ -0,0 +1,27 @@ +//===-- is_void type_traits -------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// is_void +template <typename T> struct is_void : is_same<void, remove_cv_t<T>> {}; +template <typename T> +LIBC_INLINE_VAR constexpr bool is_void_v = is_void<T>::value; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/make_signed.h b/lib/libcxx/libc/src/__support/CPP/type_traits/make_signed.h new file mode 100644 index 0000000000..00bc6be8fc --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/make_signed.h @@ -0,0 +1,41 @@ +//===-- make_signed type_traits ---------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// make_signed +template <typename T> struct make_signed; +template <> struct make_signed<char> : type_identity<char> {}; +template <> struct make_signed<signed char> : type_identity<char> {}; +template <> struct make_signed<short> : type_identity<short> {}; +template <> struct make_signed<int> : type_identity<int> {}; +template <> struct make_signed<long> : type_identity<long> {}; +template <> struct make_signed<long long> : type_identity<long long> {}; +template <> struct make_signed<unsigned char> : type_identity<char> {}; +template <> struct make_signed<unsigned short> : type_identity<short> {}; +template <> struct make_signed<unsigned int> : type_identity<int> {}; +template <> struct make_signed<unsigned long> : type_identity<long> {}; +template <> +struct make_signed<unsigned long long> : type_identity<long long> {}; +#ifdef LIBC_TYPES_HAS_INT128 +template <> struct make_signed<__int128_t> : type_identity<__int128_t> {}; +template <> struct make_signed<__uint128_t> : type_identity<__int128_t> {}; +#endif +template <typename T> using make_signed_t = typename make_signed<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/make_unsigned.h b/lib/libcxx/libc/src/__support/CPP/type_traits/make_unsigned.h new file mode 100644 index 0000000000..e5f60ae665 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/make_unsigned.h @@ -0,0 +1,46 @@ +//===-- make_unsigned type_traits -------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128 + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// make_unsigned + +template <typename T> struct make_unsigned; +template <> struct make_unsigned<char> : type_identity<unsigned char> {}; +template <> struct make_unsigned<signed char> : type_identity<unsigned char> {}; +template <> struct make_unsigned<short> : type_identity<unsigned short> {}; +template <> struct make_unsigned<int> : type_identity<unsigned int> {}; +template <> struct make_unsigned<long> : type_identity<unsigned long> {}; +template <> +struct make_unsigned<long long> : type_identity<unsigned long long> {}; +template <> +struct make_unsigned<unsigned char> : type_identity<unsigned char> {}; +template <> +struct make_unsigned<unsigned short> : type_identity<unsigned short> {}; +template <> struct make_unsigned<unsigned int> : type_identity<unsigned int> {}; +template <> +struct make_unsigned<unsigned long> : type_identity<unsigned long> {}; +template <> +struct make_unsigned<unsigned long long> : type_identity<unsigned long long> {}; +#ifdef LIBC_TYPES_HAS_INT128 +template <> struct make_unsigned<__int128_t> : type_identity<__uint128_t> {}; +template <> struct make_unsigned<__uint128_t> : type_identity<__uint128_t> {}; +#endif +template <typename T> using make_unsigned_t = typename make_unsigned<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/remove_all_extents.h b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_all_extents.h new file mode 100644 index 0000000000..bc577ca6f4 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_all_extents.h @@ -0,0 +1,41 @@ +//===-- remove_all_extents type_traits --------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +#include <stddef.h> // size_t + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// remove_all_extents +#if __has_builtin(__remove_all_extents) +template <typename T> using remove_all_extents_t = __remove_all_extents(T); +template <typename T> +struct remove_all_extents : cpp::type_identity<remove_all_extents_t<T>> {}; +#else +template <typename T> struct remove_all_extents { + using type = T; +}; +template <typename T> struct remove_all_extents<T[]> { + using type = typename remove_all_extents<T>::type; +}; +template <typename T, size_t _Np> struct remove_all_extents<T[_Np]> { + using type = typename remove_all_extents<T>::type; +}; +template <typename T> +using remove_all_extents_t = typename remove_all_extents<T>::type; +#endif + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/remove_cv.h b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_cv.h new file mode 100644 index 0000000000..2e843e0b43 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_cv.h @@ -0,0 +1,28 @@ +//===-- remove_cv type_traits -----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// remove_cv +template <class T> struct remove_cv : cpp::type_identity<T> {}; +template <class T> struct remove_cv<const T> : cpp::type_identity<T> {}; +template <class T> struct remove_cv<volatile T> : cpp::type_identity<T> {}; +template <class T> +struct remove_cv<const volatile T> : cpp::type_identity<T> {}; +template <class T> using remove_cv_t = typename remove_cv<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/remove_cvref.h b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_cvref.h new file mode 100644 index 0000000000..27591783fd --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_cvref.h @@ -0,0 +1,27 @@ +//===-- remove_cvref type_traits --------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H + +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// remove_cvref +template <typename T> struct remove_cvref { + using type = remove_cv_t<remove_reference_t<T>>; +}; +template <typename T> using remove_cvref_t = typename remove_cvref<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/remove_extent.h b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_extent.h new file mode 100644 index 0000000000..4f5ffd3453 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_extent.h @@ -0,0 +1,28 @@ +//===-- remove_extent type_traits -------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" +#include "stddef.h" // size_t + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// remove_extent +template <class T> struct remove_extent : cpp::type_identity<T> {}; +template <class T> struct remove_extent<T[]> : cpp::type_identity<T> {}; +template <class T, size_t N> +struct remove_extent<T[N]> : cpp::type_identity<T> {}; +template <class T> using remove_extent_t = typename remove_extent<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/remove_reference.h b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_reference.h new file mode 100644 index 0000000000..26ded0879f --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/remove_reference.h @@ -0,0 +1,27 @@ +//===-- remove_reference type_traits ----------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// remove_reference +template <class T> struct remove_reference : cpp::type_identity<T> {}; +template <class T> struct remove_reference<T &> : cpp::type_identity<T> {}; +template <class T> struct remove_reference<T &&> : cpp::type_identity<T> {}; +template <class T> +using remove_reference_t = typename remove_reference<T>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/true_type.h b/lib/libcxx/libc/src/__support/CPP/type_traits/true_type.h new file mode 100644 index 0000000000..55f8a535d0 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/true_type.h @@ -0,0 +1,23 @@ +//===-- true_type type_traits -----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// true_type +using true_type = cpp::bool_constant<true>; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/type_identity.h b/lib/libcxx/libc/src/__support/CPP/type_traits/type_identity.h new file mode 100644 index 0000000000..304a1ed2ce --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/type_identity.h @@ -0,0 +1,24 @@ +//===-- type_identity type_traits -------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// type_identity +template <typename T> struct type_identity { + using type = T; +}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H diff --git a/lib/libcxx/libc/src/__support/CPP/type_traits/void_t.h b/lib/libcxx/libc/src/__support/CPP/type_traits/void_t.h new file mode 100644 index 0000000000..9018860a83 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/type_traits/void_t.h @@ -0,0 +1,29 @@ +//===-- void_t type_traits --------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_VOID_T_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_VOID_T_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// void_t + +namespace detail { +template <typename... Ts> struct make_void : cpp::type_identity<void> {}; +} // namespace detail + +template <typename... Ts> +using void_t = typename detail::make_void<Ts...>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_VOID_T_H diff --git a/lib/libcxx/libc/src/__support/CPP/utility.h b/lib/libcxx/libc/src/__support/CPP/utility.h new file mode 100644 index 0000000000..083b4877c3 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/utility.h @@ -0,0 +1,18 @@ +//===-- Analogous to <utility> ----------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_H + +#include "src/__support/CPP/utility/declval.h" +#include "src/__support/CPP/utility/forward.h" +#include "src/__support/CPP/utility/in_place.h" +#include "src/__support/CPP/utility/integer_sequence.h" +#include "src/__support/CPP/utility/move.h" + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_H diff --git a/lib/libcxx/libc/src/__support/CPP/utility/declval.h b/lib/libcxx/libc/src/__support/CPP/utility/declval.h new file mode 100644 index 0000000000..9b963b9220 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/utility/declval.h @@ -0,0 +1,27 @@ +//===-- declval utility -----------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_DECLVAL_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_DECLVAL_H + +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/always_false.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// declval +template <typename T> cpp::add_rvalue_reference_t<T> declval() { + static_assert(cpp::always_false<T>, + "declval not allowed in an evaluated context"); +} + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_DECLVAL_H diff --git a/lib/libcxx/libc/src/__support/CPP/utility/forward.h b/lib/libcxx/libc/src/__support/CPP/utility/forward.h new file mode 100644 index 0000000000..085b3d16f9 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/utility/forward.h @@ -0,0 +1,35 @@ +//===-- forward utility -----------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H + +#include "src/__support/CPP/type_traits/is_lvalue_reference.h" +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// forward +template <typename T> +LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &value) { + return static_cast<T &&>(value); +} + +template <typename T> +LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &&value) { + static_assert(!is_lvalue_reference_v<T>, + "cannot forward an rvalue as an lvalue"); + return static_cast<T &&>(value); +} + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H diff --git a/lib/libcxx/libc/src/__support/CPP/utility/in_place.h b/lib/libcxx/libc/src/__support/CPP/utility/in_place.h new file mode 100644 index 0000000000..3967eb1c53 --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/utility/in_place.h @@ -0,0 +1,39 @@ +//===-- in_place utility ----------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H + +#include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR +#include "src/__support/macros/config.h" + +#include <stddef.h> // size_t + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// in_place +struct in_place_t { + LIBC_INLINE explicit in_place_t() = default; +}; +LIBC_INLINE_VAR constexpr in_place_t in_place{}; + +template <class T> struct in_place_type_t { + LIBC_INLINE explicit in_place_type_t() = default; +}; +template <class T> LIBC_INLINE_VAR constexpr in_place_type_t<T> in_place_type{}; + +template <size_t IDX> struct in_place_index_t { + LIBC_INLINE explicit in_place_index_t() = default; +}; +template <size_t IDX> +LIBC_INLINE_VAR constexpr in_place_index_t<IDX> in_place_index{}; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H diff --git a/lib/libcxx/libc/src/__support/CPP/utility/integer_sequence.h b/lib/libcxx/libc/src/__support/CPP/utility/integer_sequence.h new file mode 100644 index 0000000000..06643d505a --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/utility/integer_sequence.h @@ -0,0 +1,40 @@ +//===-- integer_sequence utility --------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H + +#include "src/__support/CPP/type_traits/is_integral.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// integer_sequence +template <typename T, T... Ints> struct integer_sequence { + static_assert(cpp::is_integral_v<T>); + template <T Next> using append = integer_sequence<T, Ints..., Next>; +}; + +namespace detail { +template <typename T, int N> struct make_integer_sequence { + using type = + typename make_integer_sequence<T, N - 1>::type::template append<N>; +}; +template <typename T> struct make_integer_sequence<T, -1> { + using type = integer_sequence<T>; +}; +} // namespace detail + +template <typename T, int N> +using make_integer_sequence = + typename detail::make_integer_sequence<T, N - 1>::type; + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H diff --git a/lib/libcxx/libc/src/__support/CPP/utility/move.h b/lib/libcxx/libc/src/__support/CPP/utility/move.h new file mode 100644 index 0000000000..b61f723e8d --- /dev/null +++ b/lib/libcxx/libc/src/__support/CPP/utility/move.h @@ -0,0 +1,27 @@ +//===-- move utility --------------------------------------------*- 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 LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H +#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H + +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/macros/attributes.h" // LIBC_INLINE +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace cpp { + +// move +template <class T> +LIBC_INLINE constexpr cpp::remove_reference_t<T> &&move(T &&t) { + return static_cast<typename cpp::remove_reference_t<T> &&>(t); +} + +} // namespace cpp +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H |
