1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:57:44 +00:00

AK+Everywhere: Make StdLibExtras templates less wrapper-y

This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
This commit is contained in:
AnotherTest 2021-04-10 18:29:06 +04:30 committed by Andreas Kling
parent d8d16dea95
commit a6e4482080
41 changed files with 650 additions and 662 deletions

View file

@ -77,28 +77,28 @@ const void* memmem(const void* haystack, size_t, const void* needle, size_t);
template<typename T>
[[nodiscard]] inline bool copy_from_user(T* dest, const T* src)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
return copy_from_user(dest, src, sizeof(T));
}
template<typename T>
[[nodiscard]] inline bool copy_to_user(T* dest, const T* src)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
return copy_to_user(dest, src, sizeof(T));
}
template<typename T>
[[nodiscard]] inline bool copy_from_user(T* dest, Userspace<const T*> src)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
return copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T));
}
template<typename T>
[[nodiscard]] inline bool copy_from_user(T* dest, Userspace<T*> src)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
return copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T));
}
@ -125,28 +125,28 @@ DEPRECATE_COPY_FROM_USER_TYPE(timeval, copy_time_from_user)
template<typename T>
[[nodiscard]] inline bool copy_to_user(Userspace<T*> dest, const T* src)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
return copy_to_user(dest.unsafe_userspace_ptr(), src, sizeof(T));
}
template<typename T>
[[nodiscard]] inline bool copy_to_user(Userspace<T*> dest, const void* src, size_t size)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
return copy_to_user(dest.unsafe_userspace_ptr(), src, size);
}
template<typename T>
[[nodiscard]] inline bool copy_from_user(void* dest, Userspace<const T*> src, size_t size)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
return copy_from_user(dest, src.unsafe_userspace_ptr(), size);
}
template<typename T>
[[nodiscard]] inline bool copy_n_from_user(T* dest, const T* src, size_t count)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
Checked size = sizeof(T);
size *= count;
if (size.has_overflow())
@ -157,7 +157,7 @@ template<typename T>
template<typename T>
[[nodiscard]] inline bool copy_n_to_user(T* dest, const T* src, size_t count)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
Checked size = sizeof(T);
size *= count;
if (size.has_overflow())
@ -168,7 +168,7 @@ template<typename T>
template<typename T>
[[nodiscard]] inline bool copy_n_from_user(T* dest, Userspace<const T*> src, size_t count)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
Checked size = sizeof(T);
size *= count;
if (size.has_overflow())
@ -179,7 +179,7 @@ template<typename T>
template<typename T>
[[nodiscard]] inline bool copy_n_to_user(Userspace<T*> dest, const T* src, size_t count)
{
static_assert(is_trivially_copyable<T>());
static_assert(IsTriviallyCopyable<T>);
Checked size = sizeof(T);
size *= count;
if (size.has_overflow())