mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 17:57:34 +00:00
AK: Allow Optional<T&> to exist
This implements Optional<T&> as a T*, whose presence has been missing since the early days of Optional. As a lot of find_foo() APIs return an Optional<T> which imposes a pointless copy on the underlying value, and can sometimes be very misleading, with this change, those APIs can return Optional<T&>.
This commit is contained in:
parent
8f1ba8db4f
commit
221ecf17d3
3 changed files with 238 additions and 1 deletions
|
@ -25,6 +25,24 @@ using TrueType = IntegralConstant<bool, true>;
|
|||
template<class T>
|
||||
using AddConst = const T;
|
||||
|
||||
template<class T>
|
||||
struct __AddConstToReferencedType {
|
||||
using Type = T;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct __AddConstToReferencedType<T&> {
|
||||
using Type = AddConst<T>&;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct __AddConstToReferencedType<T&&> {
|
||||
using Type = AddConst<T>&&;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
using AddConstToReferencedType = typename __AddConstToReferencedType<T>::Type;
|
||||
|
||||
template<class T>
|
||||
struct __RemoveConst {
|
||||
using Type = T;
|
||||
|
@ -577,6 +595,7 @@ inline constexpr bool IsOneOf = (IsSame<T, Ts> || ...);
|
|||
|
||||
}
|
||||
using AK::Detail::AddConst;
|
||||
using AK::Detail::AddConstToReferencedType;
|
||||
using AK::Detail::AddLvalueReference;
|
||||
using AK::Detail::AddRvalueReference;
|
||||
using AK::Detail::AssertSize;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue