#include <stddef.h> // For size_t
#include "array.h" // For array
-#include "type_traits.h" // For remove_cv_t
+#include "type_traits.h" // For remove_cv_t, enable_if_t, is_same_v, is_const_v
namespace __llvm_libc::cpp {
constexpr span(array<T, N> &arr)
: span_data(arr.data()), span_size(arr.size()) {}
+ template <typename U,
+ cpp::enable_if_t<!cpp::is_const_v<U> && cpp::is_const_v<T> &&
+ cpp::is_same_v<U, value_type>,
+ bool> = true>
+ constexpr span(span<U> &s) : span(s.data(), s.size()) {}
+
constexpr span(const span &s) = default;
constexpr span &operator=(const span &s) = default;
~span() = default;
namespace cpp {
template <bool B, typename T> struct enable_if;
-template <typename T> struct enable_if<true, T> {
- using type = T;
-};
+template <typename T> struct enable_if<true, T> { using type = T; };
template <bool B, typename T = void>
using enable_if_t = typename enable_if<B, T>::type;
using true_type = cpp::integral_constant<bool, true>;
using false_type = cpp::integral_constant<bool, false>;
-template <typename T> struct type_identity {
- using type = T;
-};
+template <typename T> struct type_identity { using type = T; };
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>
inline constexpr bool is_same_v = is_same<T, U>::value;
+template <class T> struct is_const : cpp::false_type {};
+template <class T> struct is_const<const T> : cpp::true_type {};
+template <class T> inline constexpr bool is_const_v = is_const<T>::value;
+
template <typename T> struct remove_cv : public type_identity<T> {};
template <typename T> struct remove_cv<const T> : public type_identity<T> {};
template <typename T> struct remove_cv<volatile T> : public type_identity<T> {};
template <typename T> inline constexpr bool is_signed_v = is_signed<T>::value;
template <typename T> struct make_unsigned;
-template <> struct make_unsigned<char> {
- using type = unsigned char;
-};
-template <> struct make_unsigned<signed char> {
- using type = unsigned char;
-};
-template <> struct make_unsigned<short> {
- using type = unsigned short;
-};
-template <> struct make_unsigned<int> {
- using type = unsigned int;
-};
-template <> struct make_unsigned<long> {
- using type = unsigned long;
-};
+template <> struct make_unsigned<char> { using type = unsigned char; };
+template <> struct make_unsigned<signed char> { using type = unsigned char; };
+template <> struct make_unsigned<short> { using type = unsigned short; };
+template <> struct make_unsigned<int> { using type = unsigned int; };
+template <> struct make_unsigned<long> { using type = unsigned long; };
template <> struct make_unsigned<long long> {
using type = unsigned long long;
};
-template <> struct make_unsigned<unsigned char> {
- using type = unsigned char;
-};
+template <> struct make_unsigned<unsigned char> { using type = unsigned char; };
template <> struct make_unsigned<unsigned short> {
using type = unsigned short;
};
-template <> struct make_unsigned<unsigned int> {
- using type = unsigned int;
-};
-template <> struct make_unsigned<unsigned long> {
- using type = unsigned long;
-};
+template <> struct make_unsigned<unsigned int> { using type = unsigned int; };
+template <> struct make_unsigned<unsigned long> { using type = unsigned long; };
template <> struct make_unsigned<unsigned long long> {
using type = unsigned long long;
};
#ifdef __SIZEOF_INT128__
-template <> struct make_unsigned<__int128_t> {
- using type = __uint128_t;
-};
-template <> struct make_unsigned<__uint128_t> {
- using type = __uint128_t;
-};
+template <> struct make_unsigned<__int128_t> { using type = __uint128_t; };
+template <> struct make_unsigned<__uint128_t> { using type = __uint128_t; };
#endif
template <typename T> using make_unsigned_t = typename make_unsigned<T>::type;