mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:57:35 +00:00
AK: Make IndexSequence use size_t
This makes it possible to use MakeIndexSequqnce in functions like: template<typename T, size_t N> constexpr auto foo(T (&a)[N]) This means AK/StdLibExtraDetails.h must now include AK/Types.h for size_t, which means AK/Types.h can no longer include AK/StdLibExtras.h (which arguably it shouldn't do anyways), which requires rejiggering some things. (IMHO Types.h shouldn't use AK::Details metaprogramming at all. FlatPtr doesn't necessarily have to use Conditional<> and ssize_t could maybe be in its own header or something. But since it's tangential to this PR, going with the tried and true "lift things that cause the cycle up to the top" approach.)
This commit is contained in:
parent
1c7ec9c770
commit
4409b33145
20 changed files with 120 additions and 96 deletions
24
AK/Tuple.h
24
AK/Tuple.h
|
@ -41,14 +41,14 @@ struct Tuple<T> {
|
|||
return const_cast<Tuple<T>&>(*this).get<U>();
|
||||
}
|
||||
|
||||
template<typename U, unsigned index>
|
||||
template<typename U, size_t index>
|
||||
U& get_with_index()
|
||||
{
|
||||
static_assert(IsSame<T, U> && index == 0, "Invalid tuple access");
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename U, unsigned index>
|
||||
template<typename U, size_t index>
|
||||
U const& get_with_index() const
|
||||
{
|
||||
return const_cast<Tuple<T>&>(*this).get_with_index<U, index>();
|
||||
|
@ -89,7 +89,7 @@ struct Tuple<T, TRest...> : Tuple<TRest...> {
|
|||
return const_cast<Tuple<T, TRest...>&>(*this).get<U>();
|
||||
}
|
||||
|
||||
template<typename U, unsigned index>
|
||||
template<typename U, size_t index>
|
||||
U& get_with_index()
|
||||
{
|
||||
if constexpr (IsSame<T, U> && index == 0)
|
||||
|
@ -98,7 +98,7 @@ struct Tuple<T, TRest...> : Tuple<TRest...> {
|
|||
return Tuple<TRest...>::template get_with_index<U, index - 1>();
|
||||
}
|
||||
|
||||
template<typename U, unsigned index>
|
||||
template<typename U, size_t index>
|
||||
U const& get_with_index() const
|
||||
{
|
||||
return const_cast<Tuple<T, TRest...>&>(*this).get_with_index<U, index>();
|
||||
|
@ -146,7 +146,7 @@ struct Tuple : Detail::Tuple<Ts...> {
|
|||
return Detail::Tuple<Ts...>::template get<T>();
|
||||
}
|
||||
|
||||
template<unsigned index>
|
||||
template<size_t index>
|
||||
auto& get()
|
||||
{
|
||||
return Detail::Tuple<Ts...>::template get_with_index<typename Types::template Type<index>, index>();
|
||||
|
@ -158,7 +158,7 @@ struct Tuple : Detail::Tuple<Ts...> {
|
|||
return Detail::Tuple<Ts...>::template get<T>();
|
||||
}
|
||||
|
||||
template<unsigned index>
|
||||
template<size_t index>
|
||||
auto& get() const
|
||||
{
|
||||
return Detail::Tuple<Ts...>::template get_with_index<typename Types::template Type<index>, index>();
|
||||
|
@ -179,37 +179,37 @@ struct Tuple : Detail::Tuple<Ts...> {
|
|||
static constexpr auto size() { return sizeof...(Ts); }
|
||||
|
||||
private:
|
||||
template<unsigned... Is>
|
||||
template<size_t... Is>
|
||||
Tuple(Tuple&& other, IndexSequence<Is...>)
|
||||
: Detail::Tuple<Ts...>(move(other.get<Is>())...)
|
||||
{
|
||||
}
|
||||
|
||||
template<unsigned... Is>
|
||||
template<size_t... Is>
|
||||
Tuple(Tuple const& other, IndexSequence<Is...>)
|
||||
: Detail::Tuple<Ts...>(other.get<Is>()...)
|
||||
{
|
||||
}
|
||||
|
||||
template<unsigned... Is>
|
||||
template<size_t... Is>
|
||||
void set(Tuple&& other, IndexSequence<Is...>)
|
||||
{
|
||||
((get<Is>() = move(other.get<Is>())), ...);
|
||||
}
|
||||
|
||||
template<unsigned... Is>
|
||||
template<size_t... Is>
|
||||
void set(Tuple const& other, IndexSequence<Is...>)
|
||||
{
|
||||
((get<Is>() = other.get<Is>()), ...);
|
||||
}
|
||||
|
||||
template<typename F, unsigned... Is>
|
||||
template<typename F, size_t... Is>
|
||||
auto apply_as_args(F&& f, IndexSequence<Is...>)
|
||||
{
|
||||
return forward<F>(f)(get<Is>()...);
|
||||
}
|
||||
|
||||
template<typename F, unsigned... Is>
|
||||
template<typename F, size_t... Is>
|
||||
auto apply_as_args(F&& f, IndexSequence<Is...>) const
|
||||
{
|
||||
return forward<F>(f)(get<Is>()...);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue